@plan3-relate/hapi-common-auth

1.3.4 • Public • Published

Hapi Common Auth Plugin Build Status

An auth wrapper for hapi.js

Installtion

npm install @plan3-relate/hapi-common-auth

Usage

const Hapi = require('hapi');
const server = new Hapi.Server();
const commonAuth = require('@plan3-relate/hapi-common-auth');


// register the plugin
server.register({
    register: commonAuth,
    options: {
        jwt: {
            publicKey: 'public-key',
            nonExpiringIds: ['allowed-id-1', 'allowed-id-2'] // optional
        },
        bearer: {
            tokens: {...}
        },
        plan3Key: {
            tokens: {...}
        }
    }
});

Adding additional credentials

Bearer and Plan3Key strategy resolves newsroom as part credentials by default. One could change this behaviour by defining addtionalCredentials object in the plugin options. Those will be merged into credentials object returned by plugin.

Example:

// register the plugin
server.register({
    register: commonAuth,
    options: {
        bearer: {
            tokens: {
                exampleToken: 'some newsroom'
            },
            additionalCredentials: {
                role: 'admin',
                origin: 'bearer'
            }
        }
    }
});

That will result in request.auth.credentials Object to equal:

{
    "newsroom": "some newsroom",
    "role": "admin",
    "origin": "bearer"
}

Readme

Keywords

Package Sidebar

Install

npm i @plan3-relate/hapi-common-auth

Weekly Downloads

0

Version

1.3.4

License

MIT

Unpacked Size

19.6 kB

Total Files

8

Last publish

Collaborators

  • plan3-relate