An auth wrapper for hapi.js
npm install @plan3-relate/hapi-common-auth
constHapi=require('hapi');constserver=newHapi.Server();constcommonAuth=require('@plan3-relate/hapi-common-auth');// register the pluginserver.register({register: commonAuth,options: {jwt: {publicKey: 'public-key',nonExpiringIds: ['allowed-id-1','allowed-id-2']// optional},bearer: {tokens: {...}},plan3Key: {tokens: {...}}}});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 pluginserver.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"
}