GET cases/{caseSystemId} works in postman, always returns 401 in php

I am trying to get a simple get request to work in php, that I've accomplished with postman without issue.

In postman, the outputted http code is the following:

GET /v1/cases/0a599156-6eb7-1e40-9bb3-2aae00039721 HTTP/1.1
Host: rms-world-check-one-api-pilot.thomsonreuters.com
Date: Fri, 06 Dec 2019 16:22:22 GMT
Authorization: Signature keyId="0b8f7e24-16d0-4672-9234-9b07b84d90d3",algorithm="hmac-sha256",headers="(request-target) host date",signature="N48t26VhJFS9KQZOqqIRumanWxfZEWwzJcRDF76f07c="
User-Agent: PostmanRuntime/7.19.0
Accept: */*
Cache-Control: no-cache
Postman-Token: d193cb45-f40d-4231-ad73-a203f00357b9,be6e8a64-807b-4184-88d3-fb1a0772b282
Host: rms-world-check-one-api-pilot.thomsonreuters.com
Accept-Encoding: gzip, deflate
Connection: keep-alive
cache-control: no-cache

And I get the information of the case back successfully.



my php code is as follows:

$curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://rms-world-check-one-api-pilot.thomsonreuters.com/v1/cases/0a599156-6eb7-1e40-9bb3-2aae00039721",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "GET",
      CURLOPT_POSTFIELDS => "",
      CURLOPT_HTTPHEADER => array(
        "Accept: */*",
        "Accept-Encoding: gzip, deflate",
        "Authorization: Signature keyId=\"0b8f7e24-16d0-4672-9234-9b07b84d90d3\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date\",signature=\"N48t26VhJFS9KQZOqqIRumanWxfZEWwzJcRDF76f07c=\"",
        "Cache-Control: no-cache",
        "Connection: keep-alive",
        "Date: Fri, 06 Dec 2019 16:22:22 GMT",
        "Host: rms-world-check-one-api-pilot.thomsonreuters.com",
        "cache-control: no-cache"
      ),
    ));

    $response = curl_exec($curl);
    $info = curl_getinfo($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo print_r($response);
    }

    echo print_r($info);

And $response is always blank, and $info always shows me a 401 status code.

Best Answer

  • @d.marcella

    How are you defining your hmac function? Can you please provide the code snippet of the function that is generating the base64 encoded HMAC signature?


    You will have to write a function to generate a HMAC and then append it in the authorization header as below.

    Authorization: Signature keyId=\"{{API-KEY}}",algorithm=\"hmac-sha256\",headers=\"(request-target) host date\",signature=\"{{BASE64-HMAC}}\"" 

    where {{BASE64-HMAC}} is the HMAC signature generated by hashing the API secret and the dataToSign variable.

Answers