fastify-aws-cognito
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

fastify-aws-cognito

Build Status Coverage Status Known vulnerabilities npm version npm downloads

AWS Cognito JWT verification for Fastify.

Install

npm install fastify-aws-cognito  

Or, using yarn:

yarn add fastify-aws-cognito  

Usage

const fastify = require("fastify")();  
  
fastify  
  .register(require("fastify-aws-cognito"), {  
    region: "<region>",  
    userPoolId: "<user pool id>"  
  })  
  .after(error => {  
    if (error) throw error;  
  
    fastify.get("/", { preValidation: [fastify.cognito.verify] }, async request => request.token);  
  })  
  .listen(3000);  

API

plugin(instance, options)

instance

Type: fastify.FastifyInstance
A fastify instance to be decorated. This value will be provided by the framework when calling fastify.register.

options

Type: object

region

Type: string
Required.

Region where user pool was created. e.g: us-east-1.

userPoolId

Type: string
Required.

Id of the AWS Cognito user pool from which the token was generated. e.g: us-east-1_1234abcd

allowedAudiences

Type: string[]
Optional.

A list of JWT Audiences to validate the token. Useful if you'd like to restrict which app clients can access your server.

instance.cognito.verify(request)

A fastify handler that will reject any request with an invalid or missing JWT.

Note: This handler returns a Promise and (currently) does not receive a callback.

request

Type: fastify.FastifyRequest Required.

fastify request to be verified.

FastifyRequest.verifyCognito()

Verifies the calling request.

Readme

Keywords

Package Sidebar

Install

npm i fastify-aws-cognito

Weekly Downloads

58

Version

1.1.0

License

MIT

Unpacked Size

87.7 kB

Total Files

29

Last publish

Collaborators

  • francisbrito