question

Upvotes
1 0 0 0

I am working on calling the World Check One API from ServiceNow and need CRyptjswrapper script include

Script include -
var refinitivWCUtils = Class.create();

refinitivWCUtils.prototype = {

initialize: function() {},

getGroupsAuthHeader: function() {

// Retrieve environment properties

var environment = {

"gateway-url": gs.getProperty('x_cbre2_generic_ap.refinitiv.gateway_url'),

"gateway-host": gs.getProperty('x_cbre2_generic_ap.refinitiv.gateway_host'),

"content": "application/json",

"api-key": gs.getProperty('x_cbre2_generic_ap.refinitiv.api_key')

};

// Manually set the date, this can be dynamically generated as well

var dateSent = new Date().toUTCString(); // Generates the current UTC date string

// Construct the dataToHash string

var dataToHash = "(request-target): get " + environment["gateway-url"] + "groups\n" +

"host: " + environment["gateway-host"] + "\n" +

"date: " + dateSent + "\n" +

"content-type: " + environment["content"];

// Generate HMAC

var hmac = this._generateHash(dataToHash);

// Create the Authorization header

var authHeader = "Signature keyId=\"" + environment["api-key"] + "\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type\",signature=\"" + hmac + "\"";

// Log debugging information

var debug = {

"environment": environment,

"dataToHash": dataToHash,

"hmac": hmac

};

gs.info('Generated Groups Auth Header Debug: ' + JSON.stringify(debug));

return authHeader;

},

getSimpleScreeningRequestAuthHeader: function(dateSent, payload) {

// Calculate content length from payload

var contentLength = unescape(encodeURIComponent(payload)).length;

// Retrieve environment properties

var environment = {

"gateway-url": gs.getProperty('x_cbre2_generic_ap.refinitiv.gateway_url'),

"gateway-host": gs.getProperty('x_cbre2_generic_ap.refinitiv.gateway_host'),

"content": "application/json",

"api-key": gs.getProperty('x_cbre2_generic_ap.refinitiv.api_key')

};

// Construct the dataToHash string

var dataToHash = "(request-target): post " + environment["gateway-url"] + "cases/screeningRequest\n" +

"host: " + environment["gateway-host"] + "\n" +

"date: " + dateSent + "\n" +

"content-type: " + environment["content"] + "\n" +

"content-length: " + contentLength + "\n" +

payload;

// Generate HMAC

var hmac = this._generateHash(dataToHash);

// Create the Authorization header

var authHeader = "Signature keyId=\"" + environment["api-key"] + "\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type content-length\",signature=\"" + hmac + "\"";

// Log debugging information

var debug = {

"environment": environment,

"dataToHash": dataToHash,

"hmac": hmac

};

gs.info('Generated Simple Screening Request Auth Header Debug: ' + JSON.stringify(debug));

return authHeader;

},

// Method to generate HMAC-SHA256 hash and convert it to Base64

_generateHash: function(dataToHash) {

var hmacUtil = new x_cbre2_generic_ap.CryptoJS_Wrapper();

var secret = gs.getProperty('x_cbre2_generic_ap.refinitiv.api_secret');

// Generate HMAC-SHA256 hash

var hash = hmacUtil.HmacSHA256(dataToHash, secret);

// Convert hash to Base64

return hmacUtil.convertToBase64(hash);

},

type: 'refinitivWCUtils'

};

Need CryptoJS_Wrapper script include to convert the hmac signature and generate the token and return it.

Code to call:


var dateToday = new Date().toGMTString();

var authHeaderString = new x_cbre2_generic_ap.refinitivWCUtils().getGroupsAuthHeader();

try {

var endPoint = "https://api-worldcheck.refinitiv.com/v2/groups";

r = new sn_ws.RESTMessageV2('World check one', 'Default GET');

r.setStringParameterNoEscape('authorizarionString', authHeaderString);

r.setStringParameterNoEscape('currentDate', dateToday);

r.setStringParameterNoEscape('endPoint', endPoint);

// r.setStringParameterNoEscape('contentLength', contentLength);

//r.setStringParameter('payload', restBody);

var response = r.execute();

var responseBody = response.getBody();

var httpStatus = response.getStatusCode();

var debug = {

"date": dateToday,

"endPoint": endPoint,

"httpStatus": httpStatus

}

gs.print(JSON.stringify(debug));

gs.print('authHeaderString is: ' + authHeaderString);

}

catch(ex) {

var message = ex.message;

gs.print('error caught, message: ' + message);

}

#technologyworldcheck-one-apirefinitiv-data-librariesapi-key
icon clock
10 |1500

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

1 Answer

· Write an Answer
Upvotes
1.2k 2 2 3

Hello @mohammedabdul.azeem - thank you for reaching out! What is the question at hand?
Regardless, I'm attaching our HMAC Walkthrough for your reference:
World-Check One API HMAC Walkthrough July 2022 (2).pdf

Best regards,

Judith


icon clock
10 |1500

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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