Skip to content

Latest commit

 

History

History
69 lines (56 loc) · 1.49 KB

README.md

File metadata and controls

69 lines (56 loc) · 1.49 KB

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"
}