For a deeper look into our World Check One API, look into:

Overview |  Quickstart |  Documentation |  Downloads

question

Upvotes
Accepted
21 0 2 2

c# code access unauthorized

Hello,

The JS code below allows me to create a new case:

But when I want to translate it into my C# application, I probably miss one step because I receive un unauthorized acces:

var environmentContent = "application/json";
            var currentDate = DateTimeOffset.UtcNow;
            var content = new StringContent(serializedElement);
            var contentLength = Uri.EscapeUriString(serializedElement).Length;

            var dataToSign = "(request-target): post /v2/cases\n" +
                                "host: rms-world-check-one-api-pilot.thomsonreuters.com\n" +
                                "date: " + currentDate + "\n" +
                                "content-type: " + environmentContent + "\n" +
                                "content-length: " + contentLength + "\n" +
                                content;

            var provider = new System.Security.Cryptography.HMACSHA256(Convert.FromBase64String(this.WorldCheckConfiguration.ApiSecret));
            var hash = provider.ComputeHash(Encoding.UTF8.GetBytes(dataToSign));
            var hmac = Convert.ToBase64String(hash);
            var authorisation = "Signature keyId=\"" + this.WorldCheckConfiguration.ApiKey + 
                            "\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type content-length\",signature=\"" + 
                            hmac + "\"";

            this.HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(environmentContent));
            this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("basic", authorisation);
            this.HttpClient.DefaultRequestHeaders.Date = currentDate;          

            var url = this.WorldCheckConfiguration.ApiBaseUrl + "cases";
            var response = await this.HttpClient.PostAsync(url, content);
world-checkworld-check-onec#
1.png (32.6 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Hi @prabhjyot.mandla

Could you please help the client with the follow-up question below?

Upvotes
Accepted
21 0 2 2

Don't you have the same example as JS for Postman, but in C#?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
548 1 1 1

@frederic.gaillard,

Can you please share the request and the response headers of the failed request?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
21 0 2 2

RequestUri: https://rms-world-check-one-api-pilot.thomsonreuters.com/v2/cases

RequestContent:

{

"groupId": "5nzbfkdmfcqy1fdst06q9j07c",

"entityType": "INDIVIDUAL",

"providerTypes": [

"WATCHLIST"

],

"name": "Frederic John Doe",

"nameTransposition": true,

"secondaryFields": []

}


And response (unauthorized):


3.png (26.2 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
548 1 1 1

@frederic.gaillard,

Could you please share the request and response details in the below format, so that we may investigate?

Request headers :

Date: Fri, 05 Feb 2021 03:44:19 GMT
Content-Type: application/json
Authorization: Signature keyId="XXXX-XXXXX-XXXXX",algorithm="hmac-sha256",headers="(request-target) host date content-type content-length",signature="RhiHURoE/NC+98L97Q+gZClcPqKRVJtAhB4dae/u+0w="
Content-Length: 524


Response headers :

Date: Wed, 10 Feb 2021 09:12:14 GMT 
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
21 0 2 2

Ok, sorry.


Request headers:

Date: {15.02.2021 09:45:24 +00:00}

Authorization: Signature keyId="61bf9346-7996-493b-851c-6ecd8c22bfa6",algorithm="hmac-sha256",headers="(request-target) host date content-type content-length",signature="y530hl3Z9bii+rLs2A9Z6OlBWlGvGad3s6V2D/BkmZQ="

Accept: {application/json }

Content-Length: 342


Response headers

Date: {15.02.2021 09:46:05 +00:00}

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Can you please adjust the system clock time? It appears that the clock time difference between the request and response is over 30 seconds. The allowed time difference is of 30 seconds and as per Network Time Protocol for the authentication. Once adjusted, please try again.

If it still fails after adjusting the clock, please share the latest request and the response headers.

Upvotes
21 0 2 2

Request headers:

Date: {15.02.2021 11:56:31 +00:00}

Authorization: Signature keyId="61bf9346-7996-493b-851c-6ecd8c22bfa6",algorithm="hmac-sha256",headers="(request-target) host date content-type content-length",signature="m/nfY4f0GjpJbitiEWxQwyGubU+c7VQ6Y9DLh8jIE44="

Accept: {application/json }

Content-Length: 342


Response headers

Date: {15.02.2021 11:56:32 +00:00}

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
548 1 1 1

@frederic.gaillard,

Can you please share the dataToSign format which you are using to form the hmac?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
21 0 2 2

With the typed variables


1.png (36.8 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

@frederic.gaillard,

Can we have a quick call to investigate on the cause of 401 error? I will drop you an email separately. Please revert back to the email.

Upvotes
548 1 1 1

The issue has been resolved after sharing the sample code requests in C#.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea