hapi-auth-bearer-simple
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -51,24 +51,24 @@ 'use strict'; | ||
request.headers.authorization === undefined) { | ||
reply(Boom.unauthorized('NO_AUTHORIZATION_HEADER', 'bearerAuth'), null, {}); | ||
} else { | ||
var headerParts = request.headers.authorization.split(' '); | ||
return reply(Boom.unauthorized('NO_AUTHORIZATION_HEADER', 'bearerAuth'), null, {}); | ||
} | ||
if (headerParts[0].toLowerCase() !== 'bearer') { | ||
return reply(Boom.notAcceptable('Token should be given in the Authorization header in "Bearer [token]" form. Example: "Authorization: Bearer azertyuiop0123"')); | ||
} | ||
var headerParts = request.headers.authorization.split(' '); | ||
internals.token = headerParts[1]; | ||
if (headerParts[0].toLowerCase() !== 'bearer') { | ||
return reply(Boom.notAcceptable('Token should be given in the Authorization header in "Bearer [token]" form. Example: "Authorization: Bearer azertyuiop0123"')); | ||
} | ||
// use provided validate function to return | ||
if (settings.exposeRequest) { | ||
settings.validateFunction(internals.token, request, function (err, isValid, credentials) { | ||
internals.token = headerParts[1]; | ||
internals.validateCallback(err, isValid, credentials, reply); | ||
}); | ||
} else { | ||
settings.validateFunction(internals.token, function (err, isValid, credentials) { | ||
// use provided validate function to return | ||
if (settings.exposeRequest) { | ||
settings.validateFunction(internals.token, request, function (err, isValid, credentials) { | ||
internals.validateCallback(err, isValid, credentials, reply); | ||
}); | ||
} | ||
internals.validateCallback(err, isValid, credentials, reply); | ||
}); | ||
} else { | ||
settings.validateFunction(internals.token, function (err, isValid, credentials) { | ||
internals.validateCallback(err, isValid, credentials, reply); | ||
}); | ||
} | ||
@@ -75,0 +75,0 @@ } |
{ | ||
"name": "hapi-auth-bearer-simple", | ||
"description": "Custom authentication plugin for Hapi using Bearer tokens", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"author": "Adri Van Houdt <adri@salesflare.com>", | ||
@@ -6,0 +6,0 @@ "private": false, |
@@ -14,2 +14,12 @@ ![Build Status](https://travis-ci.org/Salesflare/hapi-auth-bearer-simple.svg?branch=master) ![](https://david-dm.org/salesflare/hapi-auth-bearer-simple.svg) ![](https://david-dm.org/salesflare/hapi-auth-bearer-simple/dev-status.svg) ![](https://david-dm.org/salesflare/hapi-auth-bearer-simple/peer-status.svg) | ||
```javascript | ||
var validateFunction = function (token, callback) { | ||
// Use a real strategy here to check if the token is valid | ||
if (token === 'abc456789') { | ||
callback(null, true, userCredentials); | ||
} else { | ||
callback(null, false, userCredentials); | ||
} | ||
}; | ||
server.register(require('hapi-auth-bearer-simple'), function (err) { | ||
@@ -28,7 +38,10 @@ | ||
handler: function (request, reply) { | ||
reply({ success: true }); | ||
}, | ||
config: { | ||
auth: 'bearer' | ||
auth: { | ||
strategy: 'bearer', | ||
scope: 'user' // or [ 'user', 'admin' ] | ||
} | ||
} | ||
@@ -38,16 +51,6 @@ }); | ||
server.start(function () { | ||
server.log([],'Server started at: ' + server.info.uri); | ||
}); | ||
}); | ||
var validateFunction = function (token, callback) { | ||
// Use a real strategy here to check if the token is valid | ||
if (token === 'abc456789') { | ||
callback(null, true, userCredentials); | ||
} else { | ||
callback(null, false, userCredentials); | ||
} | ||
}; | ||
``` | ||
@@ -54,0 +57,0 @@ |
@@ -0,0 +0,0 @@ 'use strict'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69
18986
319