我正在努力将一个应用程序从Spring Boot1.5升级到使用OAuth和自定义授权服务器的Spring Boot2。
使用身份验证服务器和spring Boot1.5设置时,OAuth流可以正常工作。然而,在迁移到spring Boot2(目前是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,重新启动整个过程,然后无限地重定向,直到浏览器调用停止。
我已经将应用程序剥离到最基本的部分,以下是我的配置:
Applicaiton.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发布于 2019-06-28 17:58:45
我已经找到了问题的解决方案,原来Spring Boot2在请求访问令牌时似乎没有默认使用Authorization头,添加了以下配置属性解决了这个问题
security:
oauth2:
client:
authenticationScheme: headerhttps://stackoverflow.com/questions/56803785
复制相似问题