Skip to content

fix(auth): refresh access token during navigation#101

Open
GresilleSiffle wants to merge 2 commits intonaturalsolutions:devfrom
GresilleSiffle:front-regular_auth_refresh
Open

fix(auth): refresh access token during navigation#101
GresilleSiffle wants to merge 2 commits intonaturalsolutions:devfrom
GresilleSiffle:front-regular_auth_refresh

Conversation

@GresilleSiffle
Copy link
Copy Markdown

Description

This branch is a first step to fix the access token refresh, currently not performed automatically by the front end. The proposed strategy is the following:

  • step 1, refresh the access token, if needed, when a new page is loaded
  • step 2, refresh the access token, if needed, before all HTTP POST requests
  • step 3, discover limitations, and fix them :)

This branch implements the step 1.

Changes

The access token expiration date is now automatically checked during the user navigation, thanks to a new hook useRefreshToken. If both the access token and refresh token are expired, the Keycloak logout is triggered.

This will ensure that all HTTP GET requests performed during a page load are made with a valid access token.

Limitations

Note that useRefreshToken performs an asynchronous request to refresh the access token. During this process it is possible that the displayed page starts to make HTTP requests with an expired access token. If such cases happen, we will be able to use the pending state returned by the hook useRefreshToken to delay the page rendering accordingly.

Next steps

After this branch is merged, I'll implement the step 2.

@GresilleSiffle
Copy link
Copy Markdown
Author

Here is a draft of the step 2: GresilleSiffle#1

The refresh logic has been factorized to the component AuthContextProvider, to make it more reusable. The new refreshAccessToken can wrap any HTTP request to make it resilient to token expiry.

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

Successfully merging this pull request may close these issues.

1 participant