npm install hapi-jwt-auth --save
JSON Web Token (JWT) authentication plugin for HapiJS
Inspired by hapi-auth-jsonwebtoken by boketto, modified to to expose additional node-jsonwebtoken methods for convienience.
This plugin will validate a signed token in the bearer header.
You will have to register the plugin with your server object, then create a new server auth strategy. Validation will occur only on routes that require authorization.
The jwt
scheme takes the following options:
key
(required) - The private key the token was signed.validate
(optional) - Addiotional validation/user lookup, signaturefunction(token, decoded, callback)
token
- the verified signed token.decoded
- the decoded signed token.callback
- a callback function with signaturefunction(err, isValid, credentials)
err
- an internal error.isValid
(boolean) - whether the token was valid or not.credentials
- a credentials object passed back to the application inrequest.auth.credentials