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的Jetty实现与Java EE实现有很大不同,以至于它根本无法工作吗?
使用远程(OIDC)身份提供程序时,我也有类似的经历。 我发现
可能是您面临着同样的问题吗? 要进行验证,请尝试注销,然后在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.
"