Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

JSON Web Tokens (JWT) Generator?

michelhanna
Kilo Guru

What is the best way to generate a JSON Web Token (JWT) in ServiceNow?


There are heaps of implementations in different languages out there (i.e. JSON Web Tokens - jwt.io) and I wrote one myself in Java, but without a MID server I can't run that java code, and I don't want to use MID.


  1. Is there an out of the box way to generate a JWT SHA256withRSA in servicenow giving the p12 file?
  2. Or I could rewrite it in a script include. But I'll have to find an equivalent to some java classes java.security.PrivateKey, KeyStore, Signature,... which I couldn't find.
  3. The only other option that I can think of is to take one of the open source Javascript implementations, refactor it, and put it as a Script include. But it's not going to be easy.

Best also if the solution can be implemented/used in a scoped app.

Thanks,

Michel

12 REPLIES 12

I was get false when verifying the jwt.


I was able to get it working(update set above) by change the if(JSUtil.notnil(p)) to the following



var answerNil;


  if (JSUtil.isJavaObject(p)){


              answerNil = !GlideJSUtil.isNilJavaObject(p);


  }


  if(answerNil == null) {


  answerNil = !((p == null) || (typeof p == 'undefined'));


  }


if(answerNil)


Manolis Sgouro1
Tera Contributor

Hello,

 

Looks like in New York there is an API for that: https://docs.servicenow.com/bundle/newyork-platform-administration/page/administer/security/concept/...

 

cheers,

Manolis.