Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: The idTokenData is not set #49

Closed
albertwangnz opened this issue Dec 19, 2022 · 8 comments
Closed

Bug: The idTokenData is not set #49

albertwangnz opened this issue Dec 19, 2022 · 8 comments

Comments

@albertwangnz
Copy link

The idTokenData is not set.

Steps To Reproduce

  1. Get access token and id token

The current behavior

  1. {idToken} has value that can be parsed in JWT format
  2. {idTokenData} shows nothing and {JSON.stringify(idTokenData, null, 2)} shows nothing

The expected behavior

{JSON.stringify(idTokenData, null, 2)} should show the payload of the id token.

@soofstad
Copy link
Owner

soofstad commented Dec 19, 2022

Hi,
Can you please post your configuration?
Also, are you sure the access token is a valid JWT? You can try it out at pages like jwt.ms
And, are you receiving an id_token in the token request? Usually you need some special config on the provider, and a special scope for this.

@albertwangnz
Copy link
Author

Hi @soofstad , thank you for your reply.

I created a fork of the project https://github.com/albertwangnz/react-oauth2-pkce-issue49, and you can see my change in the example microsoft-auth-provider. I use AWS Cognito as the auth provider.

As you can see in the screenshot below, idTokenData is empty but idToken is not, and I can manually parse idToken to an object with the data.

Screenshot from 2022-12-20 08-32-29

@albertwangnz
Copy link
Author

I just guess the issue might be missing of using if (idToken) setIdTokenData(decodeJWT(idToken)) in the file below.

src/AuthContext.tsx

Line 195.

@anthony-vito
Copy link
Contributor

I think he's right. The idToken data is decoded and assign on line 105 of the AuthContext when a login happens...... but there is another effect() that decodes the access token that starts on line 163..... What is the purpose of that effect() ? An additional decode for both tokens might need to be placed in there.

They should both also obey the configuration "config.decodeToken" to decide on if token decoding happens at all.

@soofstad
Copy link
Owner

You are both absolutely right.
Seems I was a bit quick on the testing for the last version.

As it is now, we decode the idToken on a received token response, but not when loading the page when the idToken is already fetched.

Will get a fix for this ASAP.

@albertwangnz
Copy link
Author

Really appreciate your so fast response :-)

@soofstad
Copy link
Owner

Issue resolved by 85744ec.

Version 1.9.1 is now available with this included.

@albertwangnz
Copy link
Author

Tested and it works. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants