@uon/jwt
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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

Dependencies (1)

Dev Dependencies (1)

Package Sidebar

Install

npm i @uon/jwt

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

28.1 kB

Total Files

27

Last publish

Collaborators

  • uon-io