Title

Global

Methods

authenticate(config) → {function}

An Express authentication middleware generator.
Parameters:
Name Type Description
config JWTValidatorConfig The JWT Validator configuration.

View Source middlewares/authenticate.js, line 30

The provided configuration is invalid.
An Express authentication middleware.
function
Example
'use strict';

const express = require('express');
const { authenticate } = require('aws-cognito-express');

const app = express();

app.use(authenticate({
  region: 'us-east-2',
  userPoolId: 'us-east-2_6IfDT7ZUq',
  tokenUse: ['id', 'access'],
  audience: ['55plsi2cl0o267lfusmgaf67pf']
}));

authenticationError() → {function}

An Express authentication error handler generator.

View Source middlewares/authentication-error.js, line 23

An Express authentication error handler.
function
Example
'use strict';

const express = require('express');
const { authenticationError } = require('aws-cognito-express');

const app = express();

app.use(authenticationError());

isJWTValidatorError(err) → {boolean}

Checks if the given error was generated by the JWT Validator.
Parameters:
Name Type Description
err Error An instance of an error.

View Source lib/is-jwt-validator-error.js, line 30

Returns true if the error was generated by the JWT Validator. Otherwise returns false.
boolean
Example
'use strict';

const { JWTValidator, isJWTValidatorError } = require('aws-cognito-express');

const jwtValidator = new JWTValidator({ ... });
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';

const err = new Error('Unexpected error');
isJWTValidatorError(err);
// => false

jwtValidator.validate(token)
 .catch((err) => {
   isJWTValidatorError(err);
   // => true
 });

Type Definitions

Object

JWTValidatorConfig

The JWT Validator configuration.
Properties:
Name Type Attributes Default Description
region string <optional>
'us-east-1' The AWS Region where the Cognito User Pool was created.
userPoolId string The Cognito User Pool ID.
tokenUse Array.<string> <optional>
['access'] The accepted token uses.
audience Array.<string> A set of app client IDs that have access to the Cognito User Pool.
pems Object <optional>
null The custom pems to be used to verify the token signature.

View Source lib/jwt-validator.js, line 15