【问题标题】:Spring Security: How to find refresh token using access token at logoutSpring Security:如何在注销时使用访问令牌查找刷新令牌
【发布时间】:2017-09-04 17:48:54
【问题描述】:

在用户注销时,我也想撤销刷新令牌。问题是我在LogoutHandler 中找不到它。我只有访问令牌。 Authentication 对象也为空。

配置:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .....
        .and()
            .csrf().disable()
            .logout()
                .logoutUrl("/logout").permitAll()
                .addLogoutHandler(customLogoutHandler)
                .deleteCookies("rememberMe")
                .logoutSuccessUrl(loginPage)
        .....
        ;
}

【问题讨论】:

    标签: spring-security spring-security-oauth2


    【解决方案1】:

    您可以尝试在您的项目中对@Component("customLogoutHandler")、@Service("customLogoutHandler")、"customLogoutHandler" 等进行全局搜索。

    我在配置文件中有类似的注销成功处理程序设置,如下所示:

    @Autowired
    private LogoutSuccessHandler myLogoutSuccessHandler;
    

    然后自定义处理程序,请注意撤销刷新令牌将取决于您使用的 TokenStore 类型、JDBC、InMemory 等:

    @Component("myLogoutSuccessHandler")
    public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
    
        @Override
        public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
            //logic to revoke tokens
        }
    
    }
    

    【讨论】:

    • :(您能否通过LogoutSuccessHandler 详细说明“撤销令牌的逻辑”?
    • TokenStore 用什么?
    • 我正在使用JdbcTokenStore
    • 不确定您的授权服务器配置,您需要添加 DefaultTokenServices bean,然后从注销成功处理程序调用 revokeToken() 方法,这可能会有所帮助:stackoverflow.com/questions/21992201/…
    • DefaultTokenServices.revokeToken() 为我指明了正确的方向。问题的关键是OAuth2AccessToken.getRefreshToken() 方法。有了它,我可以找到并撤销刷新令牌。
    猜你喜欢
    • 2020-10-19
    • 2020-02-08
    • 2020-07-12
    • 2019-04-12
    • 2020-04-19
    • 2019-06-29
    • 2014-09-13
    • 2023-02-03
    • 2020-12-05
    相关资源
    最近更新 更多