Spring Security Oauth2:手机验证码授权方式配置
在oauth中有四种默认支持的认证方式
授权码(authorization-code)
隐藏式(implicit)
密码式(password):
客户端凭证(client credentials)
比如我们要实现自定义授权方式就需要配置开发自定义授权方式整合在当前spring security中, GRANT_TYPE = "api_sms_code",相当于在配置中手动添加五种授权方式。
/** * 认证服务器基本配置信息*/ @Configuration @EnableAuthorizationServer @AllArgsConstructor public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { private AuthenticationManager authenticationManager; @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) { endpoints .authenticationManager(authenticationManager) .tokenServices(tokenService()) .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST).tokenGranter((grantType, tokenRequest) -> { //授权模式 {@see AuthorizationServerEndpointsConfigurer.getDefaultTokenGranters} CompositeTokenGranter granter = new CompositeTokenGranter( Arrays.asList( new AuthorizationCodeTokenGranter( endpoints.getTokenServices(), endpoints.getAuthorizationCodeServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory() ), new RefreshTokenGranter( endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory() ), new ImplicitTokenGranter( endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory() ),new ClientCredentialsTokenGranter( endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory() ), new ResourceOwnerPasswordTokenGranter( authenticationManager, endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory() ), new SmsCodeTokenGranter( authenticationManager, endpoints.getTokenServices(), endpoints.getClientDetailsService(), endpoints.getOAuth2RequestFactory() ) ) ); return granter.grant(grantType, tokenRequest); }); endpoints.authorizationCodeServices(authorizationCodeServices()); } }
touch fish