Skip to content

Instantly share code, notes, and snippets.

@crazyoptimist
Last active August 11, 2023 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazyoptimist/17fd1340856491a7fdd6d716c4cbd9d8 to your computer and use it in GitHub Desktop.
Save crazyoptimist/17fd1340856491a7fdd6d716c4cbd9d8 to your computer and use it in GitHub Desktop.
Verify Cognito JWT tokens
import {
CognitoJwtVerifier,
CognitoJwtVerifierSingleUserPool,
} from 'aws-jwt-verify/cognito-verifier';
const verifier: CognitoJwtVerifierSingleUserPool<{
userPoolId: string;
tokenUse: 'access' | 'id';
clientId: string;
}> = CognitoJwtVerifier.create({
userPoolId: 'cognitoUserPoolId',
clientId: 'cognitoAppIntegrationClientId',
});
console.log(verifier.verify(jwtToken))
@crazyoptimist
Copy link
Author

For passport-jwt use case, refer to the official docs, it explains what to check when verifying access/id token.

https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-verifying-a-jwt.html#amazon-cognito-user-pools-using-tokens-prerequisites

It's f***ing helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment