Last active
August 11, 2023 16:43
-
-
Save crazyoptimist/17fd1340856491a7fdd6d716c4cbd9d8 to your computer and use it in GitHub Desktop.
Verify Cognito JWT tokens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.