I’m working on an SPA that uses keycloak.js to interact with my Keycloak server. I initialize the Keycloak object with onload = ‘check-sso’ and checkLoginIFrame enabled.
If I perform the following steps:
I observe that when the site reloads, it does a quick redirection (the URL briefly changes from mysite.com to mysite.com/#state=….. then back to mysite.com). I would like to avoid having this redirection when I’m already logged in.
By debugging the code, I found out why this happens:
checkState(...)
is called (via a message from keycloak.js) during initialization…with no token (sessionState
is empty since keycloak.js is not aware of the cookie).doLogin(false)
, which is where it changes the URL, creating the unwanted redirect.So my questions are thus:
doLogin()
It will be helpful if you keep the version of keycloak same with keycloak.js. I faced with the infinite redirection as well, the version of keycloak I use is 11.0.1, well the keycloak.js was an old version. So I replace it with the file from keycloak-js-adapter-dist-11.0.1.zip(downloaded from https://www.keycloak.org/archive/downloads-11.0.1.html). Then the infinite redirection problem has gone.
I have checked that this happens after 5 seconds and only with development server (ng serve in Angular SPA), which matches the default time of checkLoginIframeInterval.
I have tried setting checkLoginIframeInterval = false in the init() method and it fixes the loop issue but I'm afraid of side effects, I would rather update the keycloak.js file.
https://www.keycloak.org/docs/latest/securing_apps/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With