apolitical-jwt-wrapper

1.0.4 • Public • Published

JS JWT Wrapper

GitHub release GitHub license CircleCI NPM

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.

Readme

Keywords

none

Package Sidebar

Install

npm i apolitical-jwt-wrapper

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

15 kB

Total Files

10

Last publish

Collaborators

  • fatimat
  • johnfield
  • paddyalton
  • floppy.uk