angulartypescriptkeycloakkeycloak-angularkeycloak-js

Keycloak - Redirect to "Confirm Logout" page when logging out after a page refresh


I'm currently using keycloak on a project and everything is working fine. With one exception...

If I login, I am redirected to my project's page and if I then logout, everything works flawlessly. But if for some reason I refresh the page after logging in, when I then logout, I am redirected to a "Confirm logout" page.

How can I disable this page / prevent it from appearing?

These are the keycloak configurations I have atm:

await keycloak.init({
  config: environment.keycloakConfig,
  loadUserProfileAtStartUp: true,
  initOptions: {
      onLoad: 'check-sso',
      checkLoginIframe: false,
      silentCheckSsoRedirectUri: window.location.origin + '/assets/keycloak/silent-check-sso.html',
      enableLogging: true
  }
});

I believe there was an option in previous versions of keycloak-js/keycloak-angular to disable this page on the logout() action but there seems to be none with the most recent versions.


Solution

  • After a few hours trying to fix this problem and endless searching, I found out that the problem was that I followed a "tutorial" which said I should do the following on logout:

    await this.keycloakService.logout(logoutUrl).then(() => {
      this.keycloakService.clearToken(); // the problem is with this line!!
    });
    

    On logout, keycloak needs the token to properly logout and if it is not present, you are redirected to the "Confirm logout" page. So, if you clear the token there, it will always redirect to that page.

    FIX:

    Just remove this.keycloakService.clearToken(); line and you are good to go.