Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-auth-bearer-simple

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-auth-bearer-simple - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

34

lib/index.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc