@groupclaes/fastify-authhandler

2.2.0 • Public • Published

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: []
}
...

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

Readme

Keywords

none

Package Sidebar

Install

npm i @groupclaes/fastify-authhandler

Weekly Downloads

3

Version

2.2.0

License

MIT

Unpacked Size

6.41 kB

Total Files

4

Last publish

Collaborators

  • flyingwraptor
  • jamie.vangeysel