Skip to content

plan3/hapi-common-auth

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published