johnbrett / hapi-auth-bearer-token

Simple Bearer authentication scheme plugin for hapi, accepts token by Header, Cookie or Query parameter.
MIT License
218 stars 46 forks source link

v6 Release Notes #146

Closed johnbrett closed 6 years ago

johnbrett commented 6 years ago

hapi-auth-bearer-token

Important Note: v6 Drops support for hapi < v17 and Node < 8, due to the nature of the hapi v17 rewrite: https://github.com/hapijs/hapi/issues/3658.

breaking changes:

Please note: as part of changes with in hapi v17, server.auth.default('simple'); must now be used when setting a default auth strategy. Default strategies can no longer be set when calling server.auth.strategy. Please be careful with this.

wy193777 commented 6 years ago

Didn't mention the plugin expect validateFunc have a callback as the last parameter and need to be called with signature

callback(isValid, credentials, artifacts) 

before 6.0.

johnbrett commented 6 years ago

Hi @wy193777 is this a question or any observation? I'm not sure I understand what you are looking for.

The following is a screenshot of the README before 6.0, where validateFunc and the callback signature are underlined:

image

https://github.com/johnbrett/hapi-auth-bearer-token/blob/8da70ac735fb4f2ba47e0958e493e90804e6d394/README.md

wy193777 commented 6 years ago

I mean put this difference here or have a link to the 5.x.x document on README.md would be better. Find the right commit from commit list isn't a very good experience.

johnbrett commented 6 years ago

Updated the release notes, thanks for pointing it out.

daguiheso commented 5 years ago

Good afternoon

I would like to know how I should create a bearer token with the library, or what is the correct way

johnbrett commented 5 years ago

This library isn't for creating bearer tokens, just for validating as part of the request lifecycle:

server.auth.strategy('simple', 'bearer-access-token', {
        allowQueryToken: true,              // optional, false by default
        validate: async (request, token, h) => {

            // here is where you validate your token
            // comparing with token from your database for example
            const isValid = token === '1234';

            const credentials = { token };
            const artifacts = { test: 'info' };

            return { isValid, credentials, artifacts };
        }
    });

How you create those tokens is up to you, can be any arbitrary string or use something like https://www.npmjs.com/package/jsonwebtoken