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);
Best Answer
-
Don't you have the same example as JS for Postman, but in C#?
0
Answers
-
Can you please share the request and the response headers of the failed request?
0 -
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):
0 -
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: 524Response headers :
Date: Wed, 10 Feb 2021 09:12:14 GMT
0 -
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}
0 -
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.
0 -
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}
0 -
Can you please share the dataToSign format which you are using to form the hmac?
0 -
With the typed variables
0 -
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.
0 -
Could you please help the client with the follow-up question below?
0 -
The issue has been resolved after sharing the sample code requests in C#.
0 -
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 689 Datastream
- 1.4K DSS
- 627 Eikon COM
- 5.2K Eikon Data APIs
- 11 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 255 ETA
- 559 WebSocket API
- 39 FX Venues
- 15 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 24 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 279 Open PermID
- 45 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 2K Refinitiv Data Platform
- 708 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 106 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 96 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛