Keycloak – 在页面刷新后注销时重定向到 “确认注销” 页面

huangapple go评论76阅读模式
英文:

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."

英文:

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.

答案1

得分: 1

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!!
});

在注销时,Keycloak 需要令牌来正确注销,如果令牌不存在,您将被重定向到“确认注销”页面。因此,如果在那里清除令牌,它将总是重定向到该页面。

修复方法:

只需删除 this.keycloakService.clearToken(); 这一行,问题就解决了。

英文:

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.

答案2

得分: 1

请检查此链接,我尝试解释这种行为的原因:

https://github.com/keycloak/keycloak/discussions/12114#discussioncomment-6927266

英文:

Check this link, I tried to explain the reasons of this behaviour

https://github.com/keycloak/keycloak/discussions/12114#discussioncomment-6927266

huangapple
  • 本文由 发表于 2023年3月9日 23:25:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75686708.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定