Class

JWTValidator

JWTValidator(config) → {JWTValidator}

Constructor

new JWTValidator(config) → {JWTValidator}

Instantiates a JWT Validator.
Parameters:
Name Type Description
config JWTValidatorConfig The JWT Validator configuration.

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

The provided configuration is invalid.
A JWT Validator instance.
JWTValidator
Example
'use strict';

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

const jwtValidator = new JWTValidator({
  region: 'us-east-2',
  userPoolId: 'us-east-2_6IfDT7ZUq',
  tokenUse: ['id', 'access'],
  audience: ['55plsi2cl0o267lfusmgaf67pf']
});

Methods

async validate(token) → {Promise.<Object>}

Validates a JSON web token.
Parameters:
Name Type Description
token string The JSON web token to validate.

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

A promise that resolves to the JWT payload if the token is valid. Otherwise, it will be rejected with the appropriate error.
Promise.<Object>
Example
'use strict';

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

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

jwtValidator.validate(token)
 .then(jwtPayload => console.log(jwtPayload))
 .catch(err => console.error(err));