fix(OIDC): Use new access_token after refresh #4853
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
When using OIDC authorisation with
automaticSilentRenew: true
, OHIF keeps using the old OIDC access_token after the token has been refreshed. Requests with an expired access_token fail with a 401 or 403 response.See https://community.ohif.org/t/fix-user-state-not-updating-during-token-refresh-in-oidc-with-keycloak-and-automaticsilentrenew-true-configuration/1065
Changes & Results
In OpenIdConnectRoutes.tsx, set the user in the userAuthenticationService after a new token is available.
Testing
Use a setup with OIDC and
automaticSilentRenew: true
. When starting OHIF, a token will be requested and the response of the token endpoint will look like this:Wait until the access token has expired (based on
expires_in
, which are seconds) and then perform a search. The request should have an authorization header with the new acccess token (from the last refresh) instead of the expired one.Please note that the value of
expires_in
varies among OIDC providers. It may be 5 minutes (as required by IHE's IUA profile, this is also the default value in Keycloak), but it may also be hours or even days.Checklist
PR
semantic-release format and guidelines.
Code
etc.)
Public Documentation Updates
additions or removals.
Tested Environment