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

Custom authentication plugin for Hapi using Bearer tokens

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
117
decreased by-49.35%
Maintainers
1
Weekly downloads
 
Created
Source

Hapi authentication plugin

hapi Bearer Token Authentication Scheme

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.

The plugin requires validating a token passed in by the bearer authorization header. The validation function is something you have to provide to the plugin.

Example:

var Hapi = require('hapi');

var server = Hapi.createServer('localhost', 8000, {
    cors: true
});

server.pack.register({
    plugin: require('hapi-auth-bearer-simple'),
    options: options
}, function (err) {

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

    // Add a standard route here as example
    server.route({ 
        method: 'GET', 
        path: '/', 
        handler: function (request, reply) {
            reply({
                success: true
            });
        }, 
        config: { 
            auth: 'basic' 
        } 
    });

    server.start(function () {
        console.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 === "123456789"){
        callback(null, true, { token: token })
    } else {
        callback(null, false, { token: token })
    }
};
  • validateFunc - (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. This object can be only the token as in the example but can also be the user ascassociated with the token

FAQs

Package last updated on 18 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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