0.1.0 • Published 7 years ago
signed-jwt v0.1.0
signed-jwt
Create and validate signed JSON Web Tokens using SHA-512.
Installation
npm install --save signed-jwt
Usage
const Token = require('signed-jwt');
const secret = 'iXytm8N6ZFmcWbCUfHC3u7mDmX4e0M1b';
const myToken = Token({ 'id': 1, 'role': 'admin' }, secret);
console.log(`Your token: ${myToken}`);
if (Token.validate(myToken, secret))
console.log('Your token is valid!');
else
console.log('Your token is not valid.');
Documentation
Token
Kind: global class
new Token(customObj, secret, validTime)
Param | Type | Description |
---|---|---|
customObj | object | an object literal which contains customized information |
secret | string | secret key |
validTime | number | the amount of miliseconds the token is valid for. Defaults to 2592000000 (30 days) |
Token.validate(token, secret) ⇒ boolean
Checks if an access token is valid
Kind: static method of Token
Param | Type | Description |
---|---|---|
token | string | the access token |
secret | string | secret key |