3.0.1 • Published 5 years ago
@coolgk/jwt v3.0.1
@coolgk/jwt
a javascript / typescript module
npm install @coolgk/jwt
a simple jwt token class
Report bugs here: https://github.com/coolgk/node-utils/issues
Examples
import { Jwt } from '@coolgk/jwt';
// OR
// const { Jwt } = require('@coolgk/jwt');
const jwt = new Jwt({secret: 'abc'});
const string = 'http://example.com/a/b/c?a=1';
const token = jwt.generate(string);
console.log(
jwt.verify(token), // { exp: 0, iat: 1512307492763, rng: 0.503008668963175, data: 'http://example.com/a/b/c?a=1' }
jwt.verify(token+'1') // false
);
const token2 = jwt.generate(string, 200);
console.log(
jwt.verify(token2), // { exp: 1512307493026, iat: 1512307492826, rng: 0.5832258275608753, data: 'http://example.com/a/b/c?a=1' }
jwt.verify(token+'1') // false
);
setTimeout(() => {
console.log(jwt.verify(token2)); // false
}, 250);
Jwt
Kind: global class
- Jwt
- new Jwt(options)
- .generate(data, [expiry]) ⇒ string
- .verify(token) ⇒ boolean | object
new Jwt(options)
Param | Type | Description |
---|---|---|
options | object | |
options.secret | string | for encryption |
jwt.generate(data, expiry) ⇒ string
Kind: instance method of Jwt
Param | Type | Default | Description |
---|---|---|---|
data | * | any data can be JSON.stringify'ed | |
expiry | number | 0 | in milliseconds 0 = never expire |
jwt.verify(token) ⇒ boolean | object
Kind: instance method of Jwt
Returns: boolean | object - - false or the payload of the token
Param | Type | Description |
---|---|---|
token | string | token to verify |
3.0.1
5 years ago
3.0.0
6 years ago
2.0.6
6 years ago
2.0.5
6 years ago
2.0.4
6 years ago
2.0.3
6 years ago
2.0.2
6 years ago
2.0.1
6 years ago
2.0.0
6 years ago
1.1.4
6 years ago
1.1.3
6 years ago
1.1.2
6 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago