项目作者: francisbrito

项目描述 :
AWS Cognito JWT verification for Fastify.
高级语言: TypeScript
项目地址: git://github.com/francisbrito/fastify-aws-cognito.git
创建时间: 2019-07-23T21:12:26Z
项目社区:https://github.com/francisbrito/fastify-aws-cognito

开源协议:

下载


fastify-aws-cognito

Build Status Coverage Status Known vulnerabilities npm version npm downloads

AWS Cognito JWT verification for Fastify.

Install

  1. npm install fastify-aws-cognito

Or, using yarn:

  1. yarn add fastify-aws-cognito

Usage

  1. const fastify = require("fastify")();
  2. fastify
  3. .register(require("fastify-aws-cognito"), {
  4. region: "<region>",
  5. userPoolId: "<user pool id>"
  6. })
  7. .after(error => {
  8. if (error) throw error;
  9. fastify.get("/", { preValidation: [fastify.cognito.verify] }, async request => request.token);
  10. })
  11. .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.

verifyJtiWith

Type: function
Optional.

A function with the signature (jti: string) => Promise<boolean> to be used to check if a given JWT id is valid or not. If not provided, all jti claims will be assumed as valid.

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.