Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

iqz-systems/jwt-wrapper

Repository files navigation

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.