Skip to content

Instantly share code, notes, and snippets.

@darknessnerd
Created October 1, 2020 08:53
Show Gist options
  • Save darknessnerd/d4d0eb475e29ac2d074c15ec7dda2cf2 to your computer and use it in GitHub Desktop.
Save darknessnerd/d4d0eb475e29ac2d074c15ec7dda2cf2 to your computer and use it in GitHub Desktop.
Build a JWT With a Private Key
const njwt = require('njwt');
const privateKey=`
-----BEGIN PRIVATE KEY-----
...
...
-----END PRIVATE KEY-----
`
const clientId = "test"; // Or load from configuration
const now = Math.floor( new Date().getTime() / 1000 ); // seconds since epoch
const claims = {
"name": "bRuN1N05"
};
const jwt = njwt.create(claims, privateKey, 'RS256')
.setIssuedAt(now)
.setIssuer(clientId)
.compact();
console.log(jwt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment