Skip to content

Add token refresh to keycloak client - #1096

Merged
veenupunyani merged 2 commits into
developfrom
Add-token-refresh-to-Keycloak-client
Jul 23, 2026
Merged

Add token refresh to keycloak client#1096
veenupunyani merged 2 commits into
developfrom
Add-token-refresh-to-Keycloak-client

Conversation

@veenupunyani

@veenupunyani veenupunyani commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

PR Summary

  • Added Keycloak access-token refresh while the user stays signed in.
  • Scheduled updateToken about 30 seconds before the access token expires (~5 min lifespan).
  • Routed protected API calls through getAccessToken so the token is refreshed before use.
  • Cleared the auth session when refresh failed or the refresh token was bad/missing.

Testing Steps

  1. Sign in -> stay on the app ~5+ minutes -> still signed in (access token refreshed in sessionstorage, check in dev tools)
  2. Break or clear the refresh token, you can change the value of refresh token in dev tool to corrupt it -> session clears and user is treated as signed out
  3. Sign out -> refresh timer stops and does not keep running, clears out tokens.

Schedule updateToken near expiry, refresh before protected API calls via getAccessToken, and clear the auth session when refresh fails or if there is corrupt refreshtoken
@veenupunyani
veenupunyani force-pushed the Add-token-refresh-to-Keycloak-client branch from 590a901 to 00d7bb5 Compare July 23, 2026 22:53
@sonarqubecloud

Copy link
Copy Markdown

@veenupunyani
veenupunyani marked this pull request as ready for review July 23, 2026 22:54

@chrsamp chrsamp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, nice PR! Thank you @veenupunyani. Token refresh tested in dev + working.

@veenupunyani
veenupunyani merged commit 4767aa6 into develop Jul 23, 2026
3 checks passed
@veenupunyani
veenupunyani deleted the Add-token-refresh-to-Keycloak-client branch July 23, 2026 23:35
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.

2 participants