2.2.0 • Published 2 years ago
@groupclaes/fastify-authhandler v2.2.0
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-authhandlerUsage:
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: []
}
...available values for requiredPermissions
{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