atlassian-jwt
JWT (JSON Web Token) encoding & decoding library for node.js. Built of jwt-simple and adds Atlassian's custom QSH (query string hash) claim.
For more information on using JWT tokens with Atlassian add-ons, please read: Understanding JWT.
Install
$ npm install atlassian-jwt
Usage
Create a JWT token
var jwt = require('atlassian-jwt');
var moment = require('moment');
var now = moment().utc();
var req = {
method: 'GET',
originalUrl: '/rest/resource/you/want'
};
var token = {
"iss": 'issuer-val',
"iat": now.unix(),
"exp": now.add(3, 'minutes').unix(),
"qsh": jwt.createQueryStringHash(req)
};
var secret = 'xxx';
var token = jwt.encode(token, secret);
console.log(token);
Decode a JWT token
var decoded = jwt.decode(token, secret);
console.log(decoded);
var decoded = jwt.decode(token, null, true);
console.log(decoded);
Miscellaneous Utilities
jwt.createQueryStringHash(req, checkBodyForParams, baseUrl)
- Create a QSH using the algorithm defined by the algorithm
jwt.createCanonicalRequest(req, checkBodyForParams, baseUrl)
- Creates a canonical request which is used to calculate the QSH for the JWT token. Prefer using #createQueryStringHash() directly
Algorithms
By default the algorithm to encode is HS256
.
The supported algorithms for encoding and decoding are HS256
, HS384
, HS512
and RS256
.
jwt.encode(payload, secret, 'HS512')