Lokicoule / nestjs-cognito

AWS Cognito utilities module for NestJS.
https://www.npmjs.com/package/@nestjs-cognito/auth
MIT License
74 stars 7 forks source link

Invalid Access Token (@nestjs-cognito/auth) #153

Closed MaiKaY closed 1 year ago

MaiKaY commented 1 year ago

Hi Loïk, do you have an idea why I am getting the Invalid Access Token in auth/lib/cognito/cognito.service.ts:42:13?

I am passing the JWT within Authorization header prefixed with Bearer to my backend system. On my frontend I am using Amplify-Auth and I am generating the token with:

const session = await Auth.currentSession();
jwt = session.getIdToken().getJwtToken();

That never made any troubles before 🙈

Lokicoule commented 1 year ago

Hello Maik, You are not sending a valid access token as explained here. From your piece of code I assume you are sending the ID token instead of the access one.

const session = await Auth.currentSession();
jwt = session.getAccessToken().getJwtToken();

With this change, I hope everything is working fine :)

Lokicoule commented 1 year ago

Hello Maik, I cannot reproduce this issue with a valid access token. I'm closing this as stale. Please let me know if this is resolved on your end afterwards. Thank you!

MaiKaY commented 1 year ago

Hi Loïk, sorry for the late response, I haven't had time the last couple of days. Thanks for the hint to use getAccessToken(), it seems to work but with the access token I am facing now another error Request is undefined or null. I am researching which library is causing this, I will let you know in case it's this library.

MaiKaY commented 1 year ago

I found the issue on my end 🙈 I used AuthorizationGuard from @nestjs-cognito/auth within my resolver but it needs to be the AuthorizationGuard from @nestjs-cognito/graphql 💡 (the sample folder helped me a lot, thanks!)