【发布时间】:2019-11-10 05:28:31
【问题描述】:
我正在努力将使用 OAuth 和自定义授权服务器的应用程序从 Spring Boot 1.5 升级到 Spring Boot 2。
OAuth 流程使用身份验证服务器及其 Spring Boot 1.5 设置正常运行。但是在迁移到 Spring Boot 2(当前为 2.1.3)之后。
我在身份验证服务器和客户端应用程序之间获得了无限重定向。重定向过程如下:
http://localhost:8080/
http://localhost:8080/login
https://auth.example.com/oauth/authorize?...
http://localhost:8080/login?code=[code1]&state=[state]
http://localhost:8080/login
https://auth.example.com/oauth/authorize?...
http://localhost:8080/login?code=[code1]&state=[state]
http://localhost:8080/login
https://auth.example.com/oauth/authorize?...
http://localhost:8080/login?code=[code1]&state=[state]
http://localhost:8080/login
https://auth.example.com/oauth/authorize?...
http://localhost:8080/login?code=[code1]&state=[state]
...
如您所见,一旦身份验证服务器使用查询字符串上的身份验证代码重定向回登录,客户端应用程序就会重定向回/login 重新启动整个过程,然后无限重定向直到浏览器调用停下来。
我已经把应用程序剥离了,这是我的配置:
应用程序.java
@SpringBootApplication
public class Application
{
public static void main( String[] args )
{
SpringApplication.run( AdminApplication.class, args );
}
}
SecurityConfig.java
@Configuration
@EnableOAuth2Sso
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
@Override
protected void configure( HttpSecurity http ) throws Exception
{
http.antMatcher( "/**" )
.authorizeRequests()
.antMatchers( "/assets/**", "/app/**", "/login*" ).permitAll()
.anyRequest().authenticated();
}
}
application.yml
security:
oauth2:
client:
clientId: xxxxxx
clientSecret: xxxxx
accessTokenUri: https://auth.example.com/oauth/token
userAuthorizationUri: https://auth.example.com/oauth/authorize
resource:
userInfoUri: https://auth.example.com/user
【问题讨论】:
标签: java spring spring-boot oauth oauth-2.0