AxaFrance / oidc-client

Light, Secure, Pure Javascript OIDC (Open ID Connect) Client. We provide also a REACT wrapper (compatible NextJS, etc.).
MIT License
572 stars 151 forks source link

How to refresh tokens when returning from the Identity Provider after editing user profile data #1267

Closed radu-cs closed 5 months ago

radu-cs commented 5 months ago

How to refresh tokens when returning from the Identity Provider after editing user profile data

Given the following scenario: In the SPA we have a link to edit the user Profile on our node.js Identity Provider. After the user changes some information (e.g. language preference, name, etc.) when returning to the SPA the information is not updated from Identity Provider but uses the previous tokens that have the old information about the user.

Is there a native way to force the token refresh when returning to the SPA? Like a query parameter that can be attached to the URL for:

<a href={`${userOidc.profile}?refreshTokens=true`}>Edit Profile</a>

Or is there any other way to force the token refresh when returning from different Identity Provider Server?

Thank you in advance for your answer.

Versions

"@axa-fr/react-oidc": "7.13.14"

OIDC config

const appURL = window.location.origin

const configuration = {
  authority: import.meta.env.VITE_OIDC_AUTHORITY,
  userinfo_endpoint: null,
  client_id: import.meta.env.VITE_OIDC_CLIENT_ID,
  monitor_session: true,
  redirect_uri: `${appURL}/authentication/callback`,
  refresh_time_before_tokens_expiration_in_second: 160,
  extras: { resource: import.meta.env.VITE_OIDC_RESOURCE },
  scope: 'openid profile email phone api offline_access',
  service_worker_only: true,
  service_worker_relative_url: '/OidcServiceWorker.js',
  silent_redirect_uri: `${appURL}/authentication/silent_callback`,
}
guillaume-chervet commented 5 months ago

Hi @radu-cs ,

Thank you for your issue. The renewTokens is available for that.

You can use it like that : https://github.com/AxaFrance/oidc-client/blob/da88573ed9574f236b486eaf9b0302f9b387e503/examples/react-oidc-demo/src/Home.tsx#L36C149-L36C167

radu-cs commented 5 months ago

Hi @radu-cs ,

Thank you for your issue. The renewTokens is available for that.

You can use it like that : https://github.com/AxaFrance/oidc-client/blob/da88573ed9574f236b486eaf9b0302f9b387e503/examples/react-oidc-demo/src/Home.tsx#L36C149-L36C167

Salut @guillaume-chervet, Thank you for your reply. I'll try it and in case that I have success I'll close the Issue or I'll be coming with follow up questions. 🙂