Fastify plugin to mock AWS Cognito for testing
var FastifyMockCognito = require('fastify-mock-cognito')
fastify.register(FastifyMockCognito, {
issuer: 'https://cognito-idp.us-east-1.amazonaws.com/us-east-1_example',
audience: 'some-random-string', // optional, but should be verified
mountWellKnown: true // default
})
const data = {
'custom:property': 'value'
}
const opts = {} // jsonwebtoken options
const token = fastify.mockCognito.sign(data, opts)
The issuer passed in as option during fastify.register
. This is usually an
url of the form https://cognito-idp.REGION.amazonaws.com/USER_POOL
,
but you may want to change this during testing to the locally mounted
/.well-known/jwks.json
, such that verification of keys happen against this
endpoint.
The audience passed in as option during fastify.register
. This is the string
that you get for a specific "app" in Cognito.
Create a new JWT token with the specified properties defined by Cognito. You can
overwrite and pass extra properties through data
, such as custom:
properties
or overwrite the user data. opts
is passed to jsonwebtoken
.
Enable the /.well-known/jwks.json
endpoint to return the
fastify.mockCognito.publicKeys
data. This will only have effect if
mountWellKnown
was true
during the plugin registration.
Disable the /.well-known/jwks.json
endpoint to return 404
.
This will only have effect if mountWellKnown
was true
during the plugin
registration.
{ keys: [...]}
list of jwks
public keys. Predefined with the RSA key from
the IETF RFC.
{ keys: [...]}
list of jwks
private keys. Predefined with the RSA key from
the IETF RFC.
npm install fastify-mock-cognito