oidc-client icon indicating copy to clipboard operation
oidc-client copied to clipboard

userInfo not available immediately after authentication

Open swaroopar opened this issue 1 year ago • 9 comments

Issue and Steps to Reproduce

Hi, Thank you first of all for the well maintained library.

We are running a React based SPA with secure routes using OidcSecure. All the routes are correctly secured. But after the authentication, we have our custom authorization step based on the roles in the OidcUserInfo.

We used the hook useOidcUser to fetch user information. But the "userInfo" is still null after the authentication is completed. Is there way to wait for userInfo to be fully instantiated after the authentication is completed and before the control continues to next React component?

useOidc -> this hook returns isAuthenticated true.

Thank you

Config -

authority: xxxx,
client_id: xxxxx,
redirect_uri: window.location.origin + "/authentication/callback",
silent_redirect_uri: window.location.origin + "/authentication/silent-callback",
scope: xxxx

Versions

├── @axa-fr/[email protected] ├── [email protected] ├── [email protected] ├── [email protected]

Screenshots

We can see here that the token itself is there. but userinfo is still null.

console.log(oidcUser)
console.log(oidcUserLoadingState)
console.log(idTokenPayload)

image

Expected

oidcUser is not null after authentication is completed.

Actual

oidcUser is null after authentication is completed.

Additional Details

  • Installed packages:

swaroopar avatar Jul 13 '23 04:07 swaroopar

Hi @swaroopar , Thank you for your issue.

I think it is possible to do it. user information comes from a fetch, but I think it is possible to hide it.

guillaume-chervet avatar Jul 13 '23 08:07 guillaume-chervet

Hi @guillaume-chervet thank you for your quick response. Would be great to have it. So that the details can be used immediately after authentication.

swaroopar avatar Jul 13 '23 08:07 swaroopar

Hi,

@guillaume-chervet I'm encountering the same issue where I need to display the user's name, role, and other relevant information retrieved from the OIDC user object right after authentication. In version 3, there was a configuration property called loadUserInfo that's no longer available. Are there any alternative approaches to achieve this in the current version?

attiqeurrehman avatar Apr 15 '24 13:04 attiqeurrehman

hi @attiqeurrehman , I will try to add it tomorrow. It is a prettry quick feature to add.

guillaume-chervet avatar Apr 15 '24 19:04 guillaume-chervet

@guillaume-chervet any update on this?

attiqeurrehman avatar Apr 17 '24 06:04 attiqeurrehman

Sorry @attiqeurrehman , I will try to do it today or friday 😀

guillaume-chervet avatar Apr 18 '24 05:04 guillaume-chervet

No problem and sounds like a plan.

attiqeurrehman avatar Apr 18 '24 06:04 attiqeurrehman

Hi @attiqeurrehman , version v7.22.4-alpha.1423 implement a preload_user_info : true Configuration property

guillaume-chervet avatar Apr 19 '24 19:04 guillaume-chervet

Will use it tomorrow and let you know.

attiqeurrehman avatar Apr 19 '24 19:04 attiqeurrehman