Spring Oauth2 SSO - 无法从 Auth 服务器注销

Spring Oauth2 SSO - Unable to logout from the Auth server

我正在使用 @EnableOauth2Sso,其架构类似于 Spring 的 oauth2 tutorial 中描述的架构:auth 服务器、启用 sso 的 zuul 代理、单独的 UI 申请等

Auth server   ----  Resource Server (Zuul app) ---- Angular UI App

问题是,当 UI 从资源服务器注销时,它成功删除了资源服务器 JSESSIONID,然后用户被重定向到主页。当用户想要再次登录时,他会被重定向到 auth 服务器,但不会要求用户输入密码,而是认为他仍然登录。身份验证服务器 JSESSIONID 仍然存在,并且不受之前资源服务器注销的影响。

我怎样才能从授权服务器注销?

这是正确的行为,当您从 Angular 应用程序注销时,它不会从 Auth 服务器注销。

示例:- 假设我们要使用 google 或 facebook 帐户登录 whosebug.com,我们不需要再次输入密码,我们正在登录 Auth 服务。

如果我们需要一次又一次地显示 SSO 登录,我们需要同时注销 Angular UI 和 OAuth 服务器。

由于没有开箱即用的 Spring OAuth2 单一注销,我们必须解决这个问题,创建一个 /revoke 端点,调用 Auth Server 从它注销:

UI:

    $http({
        method: 'POST',
        url: API + '/logout'
    }).then(function() {
        $http({
            method: 'GET',
            url: API + '/auth/oauth/session/revoke'
        }).then(function() {
            window.location = '/';
        });
    });

Zuul 服务器:

zuul:
  ...
  routes:
      authServer:
        path: /auth/**
        url: ${authServer.url}/auth/
      ...

授权服务器:

@RestController
public class RevokeController {

    @RequestMapping(value = "/oauth/session/revoke", method = RequestMethod.GET)
    public void revoke(HttpServletRequest request) throws InvalidClientException {
        request.getSession().invalidate();
    }
}