All Projects → Salesflare → hapi-auth-bearer-simple

Salesflare / hapi-auth-bearer-simple

Licence: MIT license
Hapi authentication plugin for bearer token validation

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to hapi-auth-bearer-simple

hapi-good-winston
A good reporter to send and log events with winston
Stars: ✭ 21 (+31.25%)
Mutual labels:  hapi
felicity
Javascript object constructors and sample data based on Joi schema.
Stars: ✭ 107 (+568.75%)
Mutual labels:  hapi
typesafe-hapi
Typechecking for HapiJS based on Joi schemas!
Stars: ✭ 21 (+31.25%)
Mutual labels:  hapi
hapi-doorkeeper
User authentication for web servers
Stars: ✭ 14 (-12.5%)
Mutual labels:  hapi
bearer-js
Bearer provides all of the tools to build, run and manage API integrations.
Stars: ✭ 22 (+37.5%)
Mutual labels:  bearer
hapi-cli
CLI to build API with Hapi, mongodb and mongoose. Work with Hapi V17.
Stars: ✭ 36 (+125%)
Mutual labels:  hapi
restio
HTTP Client for Dart inspired by OkHttp
Stars: ✭ 46 (+187.5%)
Mutual labels:  bearer
api.pokedextracker.com
API for pokedextracker.com
Stars: ✭ 38 (+137.5%)
Mutual labels:  hapi
hapi-plugin-graphiql
HAPI plugin for GraphiQL integration
Stars: ✭ 20 (+25%)
Mutual labels:  hapi
restler
Restler is a beautiful and powerful Android app for quickly testing REST API anywhere and anytime.
Stars: ✭ 120 (+650%)
Mutual labels:  bearer
hapi-mongo-models
📦 A hapi plugin for `mongo-models`
Stars: ✭ 101 (+531.25%)
Mutual labels:  hapi
minimal-hapi-react-webpack
Minimal Hapi + React + Webpack + HMR (hot module reloading) Sandbox
Stars: ✭ 55 (+243.75%)
Mutual labels:  hapi
embedio-extras
Additional Modules showing how to extend EmbedIO.
Stars: ✭ 43 (+168.75%)
Mutual labels:  bearer
hapi-now-auth
Hapi token auth for bearer and jwt
Stars: ✭ 43 (+168.75%)
Mutual labels:  hapi
auth-ajax
Auth token handling for Polymer
Stars: ✭ 15 (-6.25%)
Mutual labels:  bearer
guzzle-jwt-middleware
Guzzle Jwt middleware
Stars: ✭ 24 (+50%)
Mutual labels:  bearer
generator-hapi-plus
Hapi REST API generator with PostgreSql, MySql, Mongo plugins, automatic Swagger docs, authentication with JWT, logging, Docker etc
Stars: ✭ 21 (+31.25%)
Mutual labels:  hapi
my-blog
node.js vue.js nuxt.js hapi.js mysql 仿简书博客
Stars: ✭ 25 (+56.25%)
Mutual labels:  hapi
wily
Build Node.js APIs from the command line (Dead Project 😵)
Stars: ✭ 14 (-12.5%)
Mutual labels:  hapi
hapi-react-fullstack-boilerplate
Hapi, Sequelize, React, etc.
Stars: ✭ 21 (+31.25%)
Mutual labels:  hapi

Build Status dep dev peer Code Climate

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 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) {

    if (err) {
        throw err;
    }

    server.auth.strategy('bearer', 'bearerAuth', {
        validateFunction: validateFunction
    });

    // Add a standard route here as example
    server.route({
        method: 'GET',
        path: '/',
        handler: function (request, reply) {

            reply({ success: true });
        },
        config: {
            auth: {
                strategy: 'bearer',
                scope: 'user' // or [ 'user', 'admin' ]
            }
        }
    });

    server.start(function (err) {

        if (err) {
            throw err;
        }

        server.log([],'Server started at: ' + server.info.uri);
    });
});
  • validateFunction - (required) a token lookup and validation function with the signature function (token, callback)
    • token - the auth token received from the client.
    • callback - a callback function with the signature function (err, isValid, credentials) where:
      • err - any error.
      • isValid - true if both the username was found and the password matched, otherwise false.
      • credentials - an object passed back to the plugin and which will become available in the requestobject as request.auth.credentials. Normally credentials are only included when isValidis true.
  • exposeRequest - (optional / advanced) If set to true the validateFunction's this will be set to the request. This can be usefull if you have plugins that expose certain functions/objects on the request object and you want to use them in your validateFunction.

Notes

  • 100% code coverage!
  • You can chain strategies see .
  • If you have any problems and/or questions make a new issue.
  • If you want to contribute feel free to fork and add a pull request or again make an issue.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].