我目前有一个 spring security 的实现,oauth2 在 spring boot 上运行。它按预期工作,我已将访问 token 的有效期设置为 10 分钟,并将刷新 token 的有效期设置为 30 天。
但是,如果用户丢失了设备并希望该客户端被注销,我希望能够使刷新 token 无效。
我的 token 商店如下所示:
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
final JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
jwtAcccessTokenConverter.setSigningKey(this.secret);
return jwtAcccessTokenConverter;
}
@Bean
public TokenStore tokenStore(){
return new JwtTokenStore(jwtAccessTokenConverter());
}
在查看 JwtTokenStore 类之后, storeRefreshToken 和 storeAccessToken 方法按预期为空,因为 token 已签名,因此不必存储。
我的计划是将生成的刷新 token 存储在数据库中,然后将其包含为刷新 token 有效的要求。
我一直在查看 JwtTokenStore 类,看起来它可以有一个可选的 ApprovalStore。
这是解决这个问题的正确方向吗?
最佳答案
我认为这个问题与 here 中描述的非常相似.因此,您可能想查看已接受的答案。
除此之外,我还有两个想法要分享:
删除客户端
这实际上取决于您如何使用客户端 ID。但是,您当然可以删除客户端 - 这会使刷新过程失败。
停用用户
从文档:
if you inject a UserDetailsService or if one is configured globally anyway (e.g. in a GlobalAuthenticationManagerConfigurer) then a refresh token grant will contain a check on the user details, to ensure that the account is still active
因此,如果您使用的是
UserDetailsService
并且您的 token 与用户相关联,您可以停用该用户以使刷新过程失败。
关于spring-boot - 带有 jwt 的 Spring Security oauth2,撤销刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44430427/