awslabs / aws-jwt-verify

JS library for verifying JWTs signed by Amazon Cognito, and any OIDC-compatible IDP that signs JWTs with RS256, RS384, and RS512
Apache License 2.0
606 stars 42 forks source link

[BUG] #61

Closed neo-headz closed 2 years ago

neo-headz commented 2 years ago

Describe the bug I'm trying to use this package to verify Cognito JWTs in a custom authorizer Lambda for an API Gateway websocket connect route. Seems simple and easy, however I keep getting an error.

Our frontend uses amazon-cognito-identity-js to log a user into Cognito. This returns the id, access, and refresh tokens. Following the docs under Basic => Amazon Cognito the following error is thrown for both id or access token.

JsonWebTokenError: invalid algorithm at /opt/nodejs/node_modules/jsonwebtoken/verify.js:121:19 at getSecret (/opt/nodejs/node_modules/jsonwebtoken/verify.js:90:14) at Object.module.exports [as verify] (/opt/nodejs/node_modules/jsonwebtoken/verify.js:94:10) at Object.exports.verifyJwt (/var/task/index.js:79:32) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async Runtime.exports.handler (/var/task/index.js:40:21) JsonWebTokenError: invalid algorithm at /opt/nodejs/node_modules/jsonwebtoken/verify.js:121:19 at getSecret (/opt/nodejs/node_modules/jsonwebtoken/verify.js:90:14) at Object.module.exports [as verify] (/opt/nodejs/node_modules/jsonwebtoken/verify.js:94:10) at Object.exports.verifyJwt (/var/task/index.js:79:32) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async Runtime.exports.handler (/var/task/index.js:40:21)

Versions Which version of aws-jwt-verify are you using? 2.1.3

Which version of Node.js are you using? (Should be at least 14) Lambda runtime nodejs14.x

If using TypeScript, which version of TypeScript are you using? (Should be at least 4) not using

To Reproduce Example code in docs Basic => Amazon Cognito I've verified the userPoolId and clientId are correct and also verified the token "alg": "RS256" on jwt.io

neo-headz commented 2 years ago

nevermind, I realized this is my mistake!! The error is not coming from this package 😁

ottokruse commented 2 years ago

jsonwebtoken ... better switch to aws-jwt-verify ;)

Kidding, use whatever works well for you!