[英]Spring Boot 2 + OAuth2: Configure Exchange of Auth Code for Token
我已经阅读了有关配置OAuth2客户端的本Spring Boot OAuth2教程。 不幸的是,一旦“用户”通过Idp(Okta)进行身份验证,就会发生带有“代码”的重定向,从而导致以下重定向循环: /login -> /authorize... -> /login... -> /login
Firefox已检测到服务器正在以永远无法完成的方式重定向对该地址的请求。
有谁知道这个问题是什么或可能是什么,以及如何解决? 详细信息如下。
Okta配置:
登录重定向URI: http:// localhost:8080 / auth / login
注销重定向URI: http:// localhost:8080 / auth / logout
登录发起者:仅应用程序
配置属性为:
okta:
oauth2:
client:
client-id: clientId
client-secret: clientSecret
scope: openid profile email
client-authentication-scheme: form
access-token-uri: https://mydomain.oktapreview.com/oauth2/myapp/v1/token
user-authorization-uri: https://mydomain.oktapreview.com/oauth2/myapp/v1/authorize
resource:
user-info-uri: https://mydomain.oktapreview.com/oauth2/myapp/v1/userinfo
过滤器为:
private Filter filter() {
OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter(
"/login");
OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(oktaClient(), oauth2ClientContext);
filter.setRestTemplate(restTemplate);
UserInfoTokenServices tokenServices = new UserInfoTokenServices(oktaResource().getUserInfoUri(),
oktaClient().getClientId());
tokenServices.setRestTemplate(restTemplate);
filter.setTokenServices(tokenServices);
return filter;
}
WebSecurityConfigurerAdapter配置为:
@Configuration
@EnableOAuth2Client
public class WebSecConfig extends WebSecurityConfigurerAdapter {
....
@Override
public void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**").authorizeRequests()
.antMatchers("/", "/login**", "/logout**", "/v2/api-docs", "/configuration/ui",
"/configuration/security", "/swagger-resources/**", "/swagger-ui.html", "/webjars/**")
.permitAll()
.anyRequest().authenticated().and().exceptionHandling()
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")).and().csrf()
.csrfTokenRepository(
CookieCsrfTokenRepository.withHttpOnlyFalse()).and().addFilterBefore(filter(),
BasicAuthenticationFilter.class);
}
....
}
更新:解决方案是将LoginUrlAuthenticationEntryPoint("/login")
更改为LoginUrlAuthenticationEntryPoint("/")
然后重新创建授权服务器。
您应该使用默认的授权服务器或您创建的默认服务器。 如果使用默认值,则它应类似于:
https://mydomain.oktapreview.com/oauth2/default
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.