【问题标题】:Spring Oauth2 SSO - Unable to logout from the Auth serverSpring Oauth2 SSO - 无法从 Auth 服务器注销
【发布时间】:2017-09-08 12:52:44
【问题描述】:

我正在使用@EnableOauth2Sso,其架构类似于 Spring 的oauth2 tutorial 中描述的架构:身份验证服务器、启用 sso 的 zuul 代理、分离的 UI 应用程序等。

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

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

我怎样才能从身份验证服务器中注销?

【问题讨论】:

    标签: angularjs spring spring-security oauth-2.0 spring-security-oauth2


    【解决方案1】:

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

    用户界面:

        $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();
        }
    }
    

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2015-07-09
        • 1970-01-01
        • 2010-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-21
        • 2017-11-28
        • 2013-08-28
        相关资源
        最近更新 更多