🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

verify-cognito-token

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
v

verify-cognito-token

Verify JWT Tokens from AWS Cognito

1.2.4
latest
69

Supply Chain Security

100

Vulnerability

76

Quality

76

Maintenance

100

License

Repository has been archived by the owner.

Network access

Supply chain risk

This module accesses the network.

Found 1 instance in 1 package

Unpopular package

Quality

This package is not very popular.

Found 1 instance in 1 package

Version published
Weekly downloads
153
-52.92%
Maintainers
1
Weekly downloads
 
Created
Issues
8

Verify Cognito Token

Verify either the ID token or the access token provided by AWS Cognito.

This is a Node friendly refactor of AWS labs' decode-verify-jwt. The process is explained in the section Using ID Tokens and Access Tokens in your Web APIs from this AWS Document.

Install with npm install verify-cognito-token -S

Usage

// params
const params = {
  region: '<your-aws-region>',  // required
  userPoolId: '<your-user-pool-id>', // required
  debug: true // optional parameter to show console logs
}

//optional claims examples
const claims = {
  aud: '<your-app-client-id>',
  email_verified: true,
  auth_time: time => time <= 1524588564,
  'cognito:groups': groups => groups.includes('Admins')
}

const Verifier = require('verify-cognito-token');
const verifier = new Verifier(params, claims);

verifier.verify(token)
.then(result =>{
  //result will be `true` if token is valid, non-expired, and has matching claims
  //result will be `false` if token is invalid, expired or fails the claims check
})

The userPoolId parameter is available from Cognito/Manage Your User Pools/Your-Pool-Name/General Settings.

The claims parameter is an optional parameter used to match against the token's claims. Its keys are claim names and its values can be any of [string, number, boolean, function]. If the value is any of [string, number, boolean] it is checked for strict equality against the token's claim with a matching name. If it is a function, the function is run against the claim. Do not try to match against an object or an array; rather use a function to test for a particular property.

License

MIT

FAQs

Package last updated on 20 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts