fastify-authhandler
Default authentication handler hook for use in fastify backend
set env var ISSUER_ID to validate issuer
set env var CLIENT_ID to validate audience
Designed to be paired with @groupclaes/fastify-elastic
fastify wrapper.
Installation:
npm i @groupclaes/fastify-authhandler
Usage:
Add the handler by using the addAuthPreHandler
function available on the Fastify
instance
...
const fastify = new Fastify(config.wrapper)
// add authhandler to fastify instance
fastify.addAuthPreHandler(handle)
...
Add the requiredPermissions
attribute to you route
...
{
method: 'GET',
url: '/:id',
handler: controller.get,
requiredPermissions: []
}
...
requiredPermissions
available values for -
{undefined}
: authorization header will be parsed if present but is not be required -
{string}
: single permission will be verified and token is mandatory -
{string[]}
: all permissions will be verified and token is mandatory