关于java:Keycloak注销不会结束会话

Keycloak logout does not end session

我在使用Spring Framework和Jetty 8.1和Keycloak Jetty-81-Adapter 3.4的Java应用程序中使用Keycloak 3.4。

根据Keycloak文档,我应该能够在Java EE应用程序中使用HttpServletRequest从Keycloak注销。但是,即使Jetty支持HttpServletRequests,这在我的情况下也不起作用。

You can log out of a web application in multiple ways. For Java EE servlet containers, you can call HttpServletRequest.logout()..

如果我尝试以这种方式注销,我将重定向到keycloak(登录屏幕,并提供从多个领域登录中选择的选项)。但是,当我选择自己的首选领域时,我无需提供任何凭据即可立即再次登录该Web应用程序。

我尝试了另一种方法,方法是重定向到Keycloak:

For other browser applications, you can redirect the browser to
http://auth-server/auth/realms/{realm-name}/protocol/openid-connect/logout?redirect_uri=encodedRedirectUri

但它会在Keycloak日志中引发拒绝连接错误,因为Keycloak尝试直接调用我的Web应用程序。它对保持活动状态的Keycloak会话没有影响。我强烈不希望从Keycloak直接向Web应用程序进行服务器端调用。

有什么建议为什么HttpServletRequest.logout()在我的情况下不会破坏keycloak会话?
HttpServletRequest的Jetty实现与Java EE实现有很大不同,以至于它根本无法工作吗?


使用远程(OIDC)身份提供程序时,我也有类似的经历。 我发现HttpServletRequest.logout实际上确实破坏了Keycloak中的会话,但没有传播到我的远程身份提供者的注销URL。 转到远程登录站点时,它立即将我重定向回去,看到我正在进行一个活动会话。 这看起来很像是密钥斗篷会话实际上并没有失效,但是我检查了,确实是。 使用浏览器重定向到url确实在两个地方都注销了。 可能是Keycloak中的错误。

可能是您面临着同样的问题吗? 要进行验证,请尝试注销,然后在keycloak和列表会话中选择您的客户端,以查看Keycloak中是否仍然存在。


您需要将包含" request.logout()"操作的Servlet或其余部分作为受保护的资源,以便令牌可用:

请查看以下文档:
"

server passing the refresh token. If the method is executed from an
unprotected page (a page that does not check for a valid token) the
refresh token can be unavailable and, in that case, the adapter skips
the call. For this reason, using a protected page to execute
HttpServletRequest.logout() is recommended so that current tokens are
always taken into account and an interaction with the {project_name}
server is performed if needed.

"