2.0.1 • Published 5 years ago

@iqz/jwt-wrapper v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

IQZ JWT Wrapper

A minimal configuration wrapper for jsonwebtoken. Uses only RS256 algorithm to sign the token, and hence requires a key pair.

Installation

npm install -S @iqz/jwt-wrapper

Usage

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.
2.0.1

5 years ago

2.0.0

5 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago