Git Product home page Git Product logo

hapi-auth-bearer-simple's Introduction

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.

hapi-auth-bearer-simple's People

Contributors

adrivanhoudt avatar bitcloud avatar greenkeeper[bot] avatar greenkeeperio-bot avatar rbudiharso avatar xaviergeerinck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hapi-auth-bearer-simple's Issues

An in-range update of hapi is breaking the build 🚨

Version 17.0.0 of hapi was just published.

Branch Build failing 🚨
Dependency hapi
Current Version 16.6.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

hapi is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 143 commits.

There are 143 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Hapijs v17 compatible

Is this plugin compatible with hapijs v17 ?
How can I integrate it to hapijs v17?

An in-range update of code is breaking the build 🚨

Version 4.1.0 of code just got published.

Branch Build failing 🚨
Dependency code
Current Version 4.0.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As code is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 7 commits.

  • 2559673 v4.1.0
  • 38df73b print expected value in assertion messages
  • df0113b update dependencies and test Node 8
  • 461fdb1 add link to Hoek.contain() from includes()
  • 3d9dfc3 add NaN() assertion
  • d6f7d4b test Node v7 on travis
  • c11a9d3 update dependencies

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of boom is breaking the build 🚨

The dependency boom was updated from 7.2.0 to 7.2.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

boom is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of hapi is breaking the build 🚨

Version 16.5.0 of hapi just got published.

Branch Build failing 🚨
Dependency hapi
Current Version 16.4.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As hapi is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 44 commits.

  • c89269a Update statehood. Closes #3551
  • 89e2b20 Update content. Closes #3550
  • ae12c40 Drain request stream on special handlers. Closes #3480
  • 355e8eb Switch to use Boom.boomify()
  • 5269898 Update boom. Closes #3548
  • f1709a3 Update joi. Closes #3545
  • f818228 Update deps. Closes #3543. Closes #3544
  • 2afa365 Handle emitter errors in request lifecycle. Closes #3464
  • 0f70551 Optimize request emitter creation. Closes #3532
  • 23d83dd Update podium. Closes #3542
  • d54e4f6 Update hoek. Closes #3541
  • 52a03b1 Cleanup for #3539
  • b947831 Merge pull request #3539 from jeff-kilbride/feature/payload_failAction_custom_handler
  • 9f8ea61 16.5.0
  • 832ed3d Merge pull request #3526 from hapijs/wildcard-debug

There are 44 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of code is breaking the build 🚨

The devDependency code was updated from 5.2.0 to 5.2.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

code is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 3 commits.

  • b458d13 v5.2.1
  • 03d7b92 update deps and test on node 11
  • 0dfe00e Add the correct thrownAt() location when using expect().to.reject()

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of hapi is breaking the build 🚨

Version 16.3.0 of hapi just got published.

Branch Build failing 🚨
Dependency hapi
Current Version 16.2.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As hapi is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 20 commits.

  • 1a41f15 Merge pull request #3479 from AJamesPhillips/docs-16.1.1
  • 3d4f0fc Merge pull request #3461 from hapijs/socket-destroy
  • ba95396 Merge pull request #3441 from kanongil/revise-normalize
  • 279def5 Cleanup for #3409
  • 241d7b0 Merge pull request #3409 from gordysc/master
  • d2de2e7 Merge pull request #3504 from kanongil/fix-flaky-test
  • 6469604 Fix flaky test from #3472
  • 081f365 Simplify request host update
  • ca1b9aa Update host info on request.setUrl(). Closes #3430
  • c315706 Fix several request.url property issues
  • eb0a606 Minor changes to docs
  • 760f433 Add partition and dropOnError to API docs
  • 79720b9 Partially revert c88266e5
  • 2d2dfaf Add link to server cache options
  • 8da535a Docs update Might instead of May. Add other response methods of hold, send, takeover

There are 20 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Unknown authentication strategy: bearer in path

I am trying to use this module to enable bearer token on my app. However, I am getting the error shown in the title.

I am trying to implement this module to enable token authorisation in my app But I am getting error mentioned below
e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\node_modules\hoek\lib\index.js:723

I have a route file

`module.exports = [
    {
        method: 'GET',
        path: '/api/{_id?}',
        handler: function (request, reply) {
           Controller.control.get(request.params, function (err, success) {
                console.log(request.params);
                if (err) {  
                    reply(unifunc.sendError(err));
                } else {
                    reply(unifunc.sendSuccess(SuccessMsg,success)).code(200);
                }
            });
        },
        config: {
            description: 'desc',
            tags: ['api', 'oV'],
            validate: {
                headers: unifunc.authorizationHeaderObj,
                params: {
                    o_id: Joi.string().required().trim(),
                    _id: Joi.string().optional().trim()
                },
                failAction: unifunc.failActionFunction
            },
            auth: {
                strategy: 'bearer',
                scope: ['admin', 'user-{params.id}']
                },
            plugins: {
                'hapi-swagger': {
                    responseMessages: msgs
                }](url)

and a controller file in which I mentioned strategy

var bearerSimple= require('hapi-auth-bearer-simple')
authorization = Authorization.auth; // This plugin has the logic to validate the token and return the error in case it fails and I am passing accesstoken as parameter in a function in that file
var getV = function(server, params, callbackRoute){  
    server.register(
        [{
            register: bearerSimple
        }], function(err){
     if(err){
         console.log("Failed to log the plugin",err);
         throw err;
     }
     server.auth.strategy('bearer', 'bearerAuth', {
        authorization : authorization
     });
    });
    console.log(params);
    async.series([
        function(cb){}
        ]}

The error message is:

Error: Unknown authentication strategy: bearer in path: /api/orders/{order_id}/vehicles/{_id?}
    at Object.exports.assert (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\node_modules\hoek\lib\index.js:723:11)
    at e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\auth.js:152:14
    at Array.forEach (native)
    at internals.Auth._setupRoute (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\auth.js:149:24)
    at new module.exports.internals.Route (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\route.js:142:47)
    at internals.Connection._addRoute (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\connection.js:375:17)
    at internals.Connection._route (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\connection.js:367:18)
    at wrappedRoute [as _route] (e:\python_training\Training\Node\Test\Project\Backend\node_modules\newrelic\lib\instrumentation\hapi.js:222:29)
    at internals.Plugin._apply (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\plugin.js:460:14)
    at internals.Plugin.route 

 Is there any way I can resolve this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.