A minimal configuration wrapper for jsonwebtoken. Uses only RS256 algorithm to sign the token, and hence requires a key pair.
npm install -S @iqz/jwt-wrapper
Import the utilities.
import { JwtSign, JwtVerify, IJwtParams } from '@iqz/jwt-wrapper';
Initalize them as early in your app as possible.
// Do the following where you'd like to sign your tokens.
JwtSign.Instance.init({
sign: {
privateKeyFile: 'path/to/private/key'
expiryTimeSeconds: 60 * 60
},
issuer: 'Your domain',
subject: 'Test Subject'
});
// Do the following where you'd like to verify your tokens.
JwtVerify.Instance.init({
verify: {
publicKeyFile: 'path/to/public/key.pub'
},
issuer: 'Your domain',
subject: 'Test Subject'
});
Sign your tokens...
let token = await JwtSign.Instance.getToken({ payload: 'Some string' }, 'testAud');
... and verify them!
let payload = await JwtVerify.Instance.verifyToken(token, 'testAud'); // Returns { payload: 'Some string' } on successful verification.