- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2018 11:18 AM
I'm calling the Zoom.us API (https://zoom.github.io/api/) and to authenticate I need to include a JWT with my API call. However, it seems that functionality is not in ServiceNow yet.
I've found a few threads around getting the CryptoJS library into ServiceNow, but it doesn't seem to work. I did see on the live code happy hour where they we're able to get this working, but I didn't see any source files available.
I've created a Script Included called CryptoJS in the Global Scope. I've pasted the entire JS Source file named "hmac-sha256" from rollups directory from this source: https://code.google.com/archive/p/crypto-js/downloads
I've removed all the ServiceNow Class Info, and just have a plain script include with nothing but the raw JS data.
Sample:
Now, I can't figure out how to even call the Script Include inside Xplore or a Fix Script.
Appending the "global." to the CryptoJS reference doesn't seem to work. Actually, line 1 all together gives me a "TypeError: undefined is not a function." If I remove that, the code still isn't finding the library as I have a lot of undefined when I log the output from a function.
Example:
var c = new CryptoJS(); //tried this, and replacing "global" with "c" to ref, not working
function base64url(source) {
// Encode in classical base64
encodedSource = global.CryptoJS.enc.Base64.stringify(source);
// Remove padding equal characters
encodedSource = encodedSource.replace(/=+$/, '');
// Replace characters according to base64url specifications
encodedSource = encodedSource.replace(/\+/g, '-');
encodedSource = encodedSource.replace(/\//g, '_');
return encodedSource;
}
This also returns "undefined".
var stringifiedHeader = CryptoJS.enc.Utf8.parse(JSON.stringify(header));
gs.print("sh: " + stringifiedHeader);
Any suggestions or pointers how to get this library in ServiceNow?
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2018 12:34 PM
Probably you need to put it in a scoped app. (best practice anyway)
Since Jakarta ES5 is available, but global runs in compatibility mode.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2018 07:06 AM
I did finally, I put in the scoped app and it works fine.
Thanks for your help and direction!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2018 12:59 PM
Hi huntj06,
We are trying to generate JWT for one of the OUTBOUND integrations and tried with CryptoJS which you provided the link. But facing the undefined error message while using in the script.
Can you please give the steps you did to fix the issue.
Thanks
Ram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2018 09:23 AM
I'm not familiar with JWT, but make sure to have CryptoJS in a Scoped app, not in global.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2018 10:06 AM
Thank you Arnoud!
I'm trying to run below script and facing "Evaluator: org.mozilla.javascript.EcmaError: The undefined value has no properties." error on the highlighted line.
var data = {
"id": 1337,
"username": "john.doe"
};
var stringifiedHeader = x_jeffe_test_crypt.CryptoJS.enc.Utf8.parse(data);
var encodedSource = x_jeffe_test_crypt.CryptoJS.enc.Base64.stringify(stringifiedHeader);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2018 10:53 AM