seneca-jwt
This plugin provides a JSON Web Token API using jsonwebtoken.
Install
Install via npm. You will need install Seneca.js also.
npm install seneca-jwt
Setup
var seneca = ;seneca;
options
- key: (string) a shared key for signing and verifying (required if publicKey and privateKey not provided)
- privateKey: (buffer) a key file (required if key not provided)
- publicKey: (buffer) a key file (required if key not provided)
- algorithm: (string, default 'RS256') the algorithm used with privateKey and publicKey
var seneca = ; // Use a shared key stringseneca; // Use public and private keysseneca;
Provided actions
seneca-jwt
provide the following actions. (all including the {role: "jwt"}
)
generateKey - generate a new key
- arguments : none
- result:
{key: "<generated-key>"}
payload
sign - create a token with given - arguments:
payload
,key
,algorithm
key
andalgorithm
can be provided in the seneca message, otherwise they are inferred from options. - result:
{token: "<generated-token>"}
verify - Check token validity
- arguments:
token
,key
,algorithm
key
andalgorithm
can be provided in the seneca message, otherwise they are inferred from options. - result: callback called with an error if not valid
decode - Extract content of token without verifying
- arguments:
token
- result: content of token
Test
npm test