1.0.3 ā¢ Published 4 years ago
simple-tokens v1.0.3
simple-tokens
š A simple package for signing and verifying simple-tokens.
Token
The token contains two parts: a) the payload b) the signature.
- payload: base64encode(JSON.stringify(object))
- signature: SHA256(payload + '.' + secret)
- token: payload + '.' + signature
Install
Install as NPM package:
$ npm install simple-tokens
Use simple-tokens
Require simpletokens
const simpletokens = require('simple-tokens');
Set secret:
simpletokens.configure('YOUR_SECRET_FRO_ENV');
Sign token:
const payload = { id: 1 }
const token = simpletokens.sign(payload);
Verify token:
const verified = simpletokens.verify(token);
Get payload from token:
const payloadObject = simpletokens.getPayload(token);