@uon/jwt
v1.0.0
Published
A library for encoding, decoding, and verifying JWTs
Downloads
8
Readme
JWT
A simple library to encode, decode and verify JWTs.
NOTE: No browser support yet. Works on node.js apps only because of 'crypto' and Buffer dependencies.
Installation
npm i @uon/jwt
Usage
import { Encode, Decode, Verify, JwtToken, VerifyResult } from '@uon/jwt';
const payload = {
hello: 'world',
iat: Date.now(),
exp: Date.now() + 60 * 1000
};
// encode a payload to jwt string
const token_str = Encode(payload, 'my-secret', 'HS256');
// verify a token
const verify_result: VerifyResult = Verify(token_str, 'my-secret', { ... });
// verify_result.sig === true
// decode a token to its components
const token: JwtToken = Decode(token_str);
Limitations
- No support for payload encryption yet