Keycloak URL fragments do not disappear when logged in

1.4k Views Asked by At

Keycloak inserts session_state, state and code in url fragment params.. sometimes after successful login these remain on the url...

Or, when alternate routes are clicked in the app, these appear again.

Unnecessarily exposing the internals of keycloak params to users.

Is there some solution to not have these appear or delete them?

e.g. http://localhost:3000/home/#state=e625140e-c4f9-4500-858e-32c80e89f8a9&session_state=445229c3-d7eb-46e9-bfba-3339253dd17e&code=af0abde4-a60d-4f34-a101-8db5c76546b9.445229c3-d7eb-46e9-bfba-3339253dd17e.59915134-a59b-4ffb-878a-d02e7e84f2dd

Update: with more tests narrowed down the issue to occur when

  1. anything on the keycloak instance is touched. e.g. keycloak.token
  2. any function call of keycloak is invoked... then after that these params get added and removed for every url route thereafter... e.g. await keycloak.updateToken()

Keycloak Sever and js lib Version : 9.0.2

1

There are 1 best solutions below

1
On

It is not a Keycloak issue. That's how used login flow works (maybe you need different flow, which will be more suitable for your use case). Your app code (used OIDC/OAuth library) should "clean" URL fragments. Cleaning can be: exchange code for the token (in this particular case), remove URL fragments, clean browser history, etc.