Constructor
new JWTValidator(config) → {JWTValidator}
Instantiates a JWT Validator.
Parameters:
Name | Type | Description |
---|---|---|
config |
JWTValidatorConfig | The JWT Validator configuration. |
The provided configuration is invalid.
A JWT Validator instance.
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. |
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));