Hapi authentication plugin
hapi Bearer Token Authentication Scheme
What
The plugin requires validating a token passed in by the bearer authorization header or via the access_token
query param. The validation function is something you have to provide to the plugin.
How
var { // Use a real strategy here to check if the token is valid if token === 'abc456789' ; else ; }; server;
validateFunction
- (required) a token lookup and validation function with the signaturefunction (token, callback)
token
- the auth token received from the client.callback
- a callback function with the signaturefunction (err, isValid, credentials)
where:err
- any error.isValid
-true
if both the username was found and the password matched, otherwisefalse
.credentials
- an object passed back to the plugin and which will become available in therequest
object asrequest.auth.credentials
. Normally credentials are only included whenisValid
istrue
.
exposeRequest
- (optional / advanced) If set totrue
thevalidateFunction
'sthis
will be set to therequest
. This can be usefull if you have plugins that expose certain functions/objects on therequest
object and you want to use them in yourvalidateFunction
.