Skip to content

Commit

Permalink
update dependencies, readme, bump package version
Browse files Browse the repository at this point in the history
  • Loading branch information
John Brett committed Dec 15, 2015
1 parent d805ce7 commit 9d7456a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
45 changes: 28 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Hapi auth bearer token
[![Build Status](https://travis-ci.org/johnbrett/hapi-auth-bearer-token.svg?branch=master)](https://travis-ci.org/johnbrett/hapi-auth-bearer-token) [![Dependency Status](https://david-dm.org/johnbrett/hapi-auth-bearer-token.svg)](https://david-dm.org/johnbrett/hapi-auth-bearer-token) [![Test Coverage](https://codeclimate.com/github/johnbrett/hapi-auth-bearer-token/badges/coverage.svg)](https://codeclimate.com/github/johnbrett/hapi-auth-bearer-token)
# hapi auth bearer token
[![NPM Version](https://img.shields.io/npm/v/hapi-auth-bearer-token.svg)](https://npmjs.org/package/hapi-auth-bearer-token)
[![Build Status](https://travis-ci.org/johnbrett/hapi-auth-bearer-token.svg?branch=master)](https://travis-ci.org/johnbrett/hapi-auth-bearer-token)
[![Dependency Status](https://david-dm.org/johnbrett/hapi-auth-bearer-token.svg)](https://david-dm.org/johnbrett/hapi-auth-bearer-token)
[![Test Coverage](https://codeclimate.com/github/johnbrett/hapi-auth-bearer-token/badges/coverage.svg)](https://codeclimate.com/github/johnbrett/hapi-auth-bearer-token)

Lead Maintainer: [John Brett](https://github.com/johnbrett)

[**hapi**](https://github.com/spumko/hapi) Bearer and Access Token authentication scheme
[**hapi**](https://github.com/hapijs/hapi) Bearer and Access Token authentication scheme

Bearer authentication requires validating a token passed in by either the bearer authorization header, or by an access_token query parameter. The `'bearer-access-token'` scheme takes the following options:

Expand All @@ -21,47 +24,55 @@ Bearer authentication requires validating a token passed in by either the bearer
- `allowMultipleHeaders` (Default: false) - Allow multiple authorization headers in request, e.g. `Authorization: FD AF6C74D1-BBB2-4171-8EE3-7BE9356EB018; Bearer 12345678`
- `tokenType` (Default: 'Bearer') - Allow custom token type, e.g. `Authorization: Basic 12345678`

For convenience, the `request` object can be accessed from `this` within validateFunc. This allows some greater flexibility with authentication, such different authentication checks for different routes.
For convenience, the `request` object can be accessed from `this` within validateFunc. If you want to use this, you must use the `function` keyword instead of the arrow syntax. This allows some greater flexibility with authentication, such different authentication checks for different routes.

```javascript
var Hapi = require('hapi');
const Hapi = require('hapi');
const AuthBearer = require('hapi-auth-bearer-token');

var server = new Hapi.Server();
const server = new Hapi.Server();
server.connection({ port: 8080 });

server.register(require('hapi-auth-bearer-token'), function (err) {
server.register(AuthBearer, (err) => {

server.auth.strategy('simple', 'bearer-access-token', {
allowQueryToken: true, // optional, true by default
allowMultipleHeaders: false, // optional, false by default
accessTokenName: 'access_token', // optional, 'access_token' by default
validateFunc: function( token, callback ) {
validateFunc: function (token, callback) {

// For convenience, the request object can be accessed
// from `this` within validateFunc.
var request = this;

// Use a real strategy here,
// comparing with a token from your database for example
if(token === "1234"){
callback(null, true, { token: token })
} else {
callback(null, false, { token: token })
if (token === "1234") {
return callback(null, true, { token: token });
}

return callback(null, false, { token: token });
}
});
});

server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply('success');
},
config: { auth: 'simple' }
config: {
auth: 'simple',
handler: function (request, reply) {

return reply('success');
}
}
});

server.start(function () {
server.start((err) => {

if (err) {
throw err;
}
console.log('Server started at: ' + server.info.uri);
})
```
Expand Down
10 changes: 5 additions & 5 deletions package.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hapi-auth-bearer-token",
"description": "Simple Bearer authentication scheme plugin for hapi, accepts token by Header or Query parameter.",
"version": "3.1.1",
"version": "4.0.0",
"author": "John Brett <johnbrett7@gmail.com> (http://blog.johnbrett.me)",
"repository": {
"type": "git",
Expand All @@ -19,7 +19,7 @@
"authentication"
],
"engines": {
"node": ">=0.10.22"
"node": ">=4.0.0"
},
"dependencies": {
"boom": "3.x.x",
Expand All @@ -29,9 +29,9 @@
"hapi": ">=8.x.x"
},
"devDependencies": {
"hapi": "11.x.x",
"lab": "8.x.x",
"code": "2.x.x"
"code": "2.x.x",
"hapi": "^11.1.2",
"lab": "8.x.x"
},
"scripts": {
"test": "lab -a code -c -L"
Expand Down

0 comments on commit 9d7456a

Please sign in to comment.