文章目录
自定义授权模式
spring-security-oauth2除oauth2协议中4种授权模式,还有刷新token,其实也算是oauth2协议的授权模式,那么我需要自定义授权模式,例如短信验证码的授权模式该如何做呢
上一篇 spring-security-oauth2 配置(一)
本篇在上一篇的基础上进行
提示:以下是本篇文章正文内容,下面案例可供参考
一、效果预览
二、java配置
DemoAuthorizationServerConfiguration.java
之前的代码
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore)
.authenticationManager(authenticationManager)
.userDetailsService(userDetailsService)
.tokenEnhancer(tokenEnhancer)
.accessTokenConverter(jwtAccessTokenConverter);
}
现在改为:
List<TokenGranter> tokenGranters = new ArrayList<>(Collections.singletonList(endpoints.getTokenGranter()));
tokenGranters.add(new DemoSmsCodeTokenGranter(endpoints, userDetailsService));
endpoints.authenticationManager(authenticationManager)
.tokenStore(tokenStore)
.tokenGranter(new CompositeTokenGranter(tokenGranters))
.tokenEnhancer(tokenEnhancer)
.accessTokenConverter(jwtAccessTokenConverter)
.userDetailsService