Spring boot 向spring提供自定义OAuth2AccessTokenResponseClient
我有一个演示spring引导应用程序,我想配置oauth登录以及我自己的自定义令牌响应客户端 这是我的配置:Spring boot 向spring提供自定义OAuth2AccessTokenResponseClient,spring-boot,spring-security,Spring Boot,Spring Security,我有一个演示spring引导应用程序,我想配置oauth登录以及我自己的自定义令牌响应客户端 这是我的配置: @Configuration @EnableWebSecurity class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .aut
@Configuration
@EnableWebSecurity
class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.oauth2Login()
.and()
.oauth2Client()
.authorizationCodeGrant()
.accessTokenResponseClient(customAccessTokenResponseClient());
}
private OAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> customAccessTokenResponseClient() {
DefaultAuthorizationCodeTokenResponseClient client = new DefaultAuthorizationCodeTokenResponseClient();
client.setRequestEntityConverter(new CustomOAuth2AuthorizationCodeGrantRequestEntityConverter());
return client;
}
}
@配置
@启用Web安全性
类SecurityConfig扩展了WebSecurity配置适配器{
@凌驾
受保护的无效配置(HttpSecurity http)引发异常{
http
.授权请求()
.anyRequest()
.authenticated()
.及()
.oauth2Login()
.及()
.oauth2Client()
.authorizationCodeGrant()
.accessTokenResponseClient(customAccessTokenResponseClient());
}
专用OAuth2AccessTokenResponseClient customAccessTokenResponseClient(){
DefaultAuthorizationCodeTokenResponseClient=新的DefaultAuthorizationCodeTokenResponseClient();
setRequestEntityConverter(新CustomOAuth2AuthorizationCodeGrantRequestEntityConverter());
返回客户;
}
}
登录流正在运行,但我的自定义令牌响应客户端似乎未注册。我在那里放了一个断点,但是水流没有通过它。看起来它仍在使用默认设置
我是遗漏了什么还是订单错了?解决了问题
正确的配置方法如下所示:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests().anyRequest().authenticated()
.and()
.oauth2Login()
.tokenEndpoint()
.accessTokenResponseClient(customAccessTokenResponseClient());
}