AWS Cognito JWT verification for Fastify.
npm install fastify-aws-cognito
Or, using yarn
:
yarn add fastify-aws-cognito
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);
Type: fastify.FastifyInstance
A fastify
instance to be decorated. This value will be provided by the framework when calling fastify.register
.
Type: object
Type: string
Required.
Region where user pool was created. e.g: us-east-1
.
Type: string
Required.
Id of the AWS Cognito user pool from which the token was generated. e.g: us-east-1_1234abcd
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.
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.
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.
Type: fastify.FastifyRequest
Required.
fastify
request to be verified.
Verifies the calling request.