apolitical-jwt-wrapper
v1.0.4
Published
A simple wrapper for JWTs in Apolitical's JS projects
Downloads
11
Keywords
Readme
JS JWT Wrapper
Creates basic JWT tokens based on a shared secret. Simple wrapper around jsrsasign.
Installation
$ npm install --save apolitical-jwt-wrapper
Usage
There are three exposed functions, each one takes the shared secret and returns another function.
jwtCreator
Creates a new jwt.
const { jwtCreator } = require('apolitical-jwt-wrapper');
const createJwt = jwtCreator('secret');
const jwt = createJwt({ my: 'payload' });
console.log(jwt);
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJteSI6InBheWxvYWQifQ.78bnGeLf_4A3mXZhStnMo6warvE1M5QTHRJClTpnS4s
jwtValidator
const { jwtValidator } = require('apolitical-jwt-wrapper');
const isValid = jwtValidator('secret');
const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJteSI6InBheWxvYWQifQ.78bnGeLf_4A3mXZhStnMo6warvE1M5QTHRJClTpnS4s';
console.log(isValid(jwt));
true
jwtPayloadExtractor
const { jwtPayloadExtractor } = require('apolitical-jwt-wrapper');
const getPayload = jwtPayloadExtractor('secret');
const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJteSI6InBheWxvYWQifQ.78bnGeLf_4A3mXZhStnMo6warvE1M5QTHRJClTpnS4s';
console.log(getPayload(jwt));
{ my: 'payload' }
Contributing
If you want to help, that's brilliant! Have a look at our Contributing Guide. We also adhere to a Code of Conduct, so please check that out, it includes details on who to contact if you have any concerns.