jsrsasign
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2015 03:03 PM
i was tasked with integrating ServiceNow with our second-factor authentication vendor (Ping Identity). the goal was to be able to automate administrative processes that would otherwise be worked on manually and only during business hours.
this brought up the need to use JWTs for our first time. jsrsasign was the recommended javascript library per our vendor and general googling. all i had to do was get it working in ServiceNow. of the many ways this is probably possible, this is how i did it:
requirements:
- maintain original source code of jsrsasign with the least amount of modification necessary
- that it works
resources used
process:
- create script include
var jsrsasign = Class.create();
jsrsasign.prototype = {
initialize: function() {
},
type: 'jsrsasign'
};
- the entire minified source for jsrsasign will be put in the initialize function of the script include. there were some errors at first relating to window and navigator not being defined. this was resolved by declaring these as objects before pasting in the jsrsasign code. (i've spared your scroll bars by not pasting in the entire code for jsrsasign-5.0.1-all-min.js. you would paste in after line 5 in the script example below.)
var jsrsasign = Class.create();
jsrsasign.prototype = {
initialize: function () {
var navigator = {};
var window = {};
},
type: 'jsrsasign'
};
- the other error i had, and the one modification i had to make to the jsrsasign source, was with a primitive type error related to an if statement in the cryptojs library. this was worked out, thanks to a tip from chrisc., by using JSUtil.notNil. run a replace on:
if(p)
- and replace with:
if(JSUtil.notNil(p)) /*modified from original value of if(p)*/
- next, i created functions that called one of the specific functions from jsrsasign that i needed.
signJWT: function (alg, sHeader, sPayload, key, pass) {
var sign = KJUR.jws.JWS.sign(alg, sHeader, sPayload, key, pass);
return sign;
},
- i have another script include that builds and packages the required json headers/payload and sends the request up to our vendor. i run my new JWT function from that script include by calling:
new jsrsasign().signJWT(alg, sHeader, sPayload, key, pass);
results:
- instant authenticated request/response to our 3rd party app to deprovision mobile devices.
- zero-touch results for users around the clock.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2019 03:51 AM
var jsrsasign = Class.create();
jsrsasign.prototype = {
initialize: function () {
var navigator = {};
var window = {};
// jsrsasign-all-min.js starts
//TODO: replace this line with jsrsasign-all-min.js
// jsrsasign-all-min.js ends
this.KJUR = KJUR;
},
encrypt: function (test,pubKey) {
this.KJUR.crypto.Cipher.encrypt(test,pubKey);
},
type: 'jsrsasign'
};
Many thanks! If it shows "KJUR is not defined", you can set something like this. Then you can call new jsrasign().encrypt(test, pubKey) instead
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2019 07:38 AM
Hi there,
I followed all the stuff reported here, but actually I'm getting
Evaluator: org.mozilla.javascript.EcmaError: "SecureRandom" is not defined. Caused by error in script at line 288
Evaluator: org.mozilla.javascript.EcmaError: "SecureRandom" is not defined. Caused by error in script at line 5
Any advise on that?
Thanks.
KR,
Ermanno