We are trying to generate Authorization Header for API request but having an unathorizes reposne instead.
Find the Script and .Net Code below through which we are trying to request the groups API
Below is JavaScript refence file and the refence code used to implemet the CryptoJS.HmacSHA256 funtion to generate the Signature key value to be passed in Authorization Header
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>
function generateAuthHeader(dataToSign) {
var hash = CryptoJS.HmacSHA256(dataToSign, "qgq4/39BA9mar5FKcFkKzRc3E72gGRJ9mb0BJefWja6LEw4CjKh5TBXnO84p8xT+EcvQB2AFNaeO1rpZtGB1NQ==");
return hash.toString(CryptoJS.enc.Base64);
}
function GenerateHeader() {
var date = new Date().toGMTString();
var dataToSign = "(request-target): get /v1/groups\n" +
"host: api-worldcheck.refinitiv.com\n" +
"date: " + date;
var hmac = generateAuthHeader(dataToSign);
var authorisation = "Signature keyId=\"47922b3d-c807-421c-9692-c5f556525a06\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date\",signature=\"" + hmac + "\"";
var CurrentDate = document.getElementById('<%= CurrentDate.ClientID %>');
if (CurrentDate != undefined) if (CurrentDate != null) CurrentDate.value = date;
var Authorization = document.getElementById('<%= Authorization.ClientID %>');
if (Authorization != undefined) if (Authorization != null) Authorization.value = authorisation;
}
we are then using the CurrentDate and Authorization value as being set in above code in the code behind request header as below
var client = new RestClient(); var request = new RestRequest(); IRestResponse response;
client = new RestClient("https://api-worldcheck.refinitiv.com/v1/groups");
client.Timeout = -1;
request = new RestRequest(Method.GET);
request.AddHeader("Date", "Wed, 14 Apr 2021 07:26:40 GMT");
request.AddHeader("Authorization", "Signature keyId=\"47922b3d-c807-421c-9692-c5f556525a06\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date\",signature=\"mLcf0wkQ67lK2BaNRKb+HKk+A2nEhEiJN1jeEEUCoqQ=\"");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
response = client.Execute(request);
More details on Development enviorement
Microsoft vs 2015 community editon, .net framework 4.8