Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Boot 2 Oauth无限重定向_Java_Spring_Spring Boot_Oauth_Oauth 2.0 - Fatal编程技术网

Java Spring Boot 2 Oauth无限重定向

Java Spring Boot 2 Oauth无限重定向,java,spring,spring-boot,oauth,oauth-2.0,Java,Spring,Spring Boot,Oauth,Oauth 2.0,我正在努力将使用OAuth和自定义授权服务器的应用程序从SpringBoot1.5升级到SpringBoot2 OAuth流使用auth服务器及其spring boot 1.5设置正常运行。但是,在当前迁移到SpringBoot2.1.3之后 我在auth服务器和客户机应用程序之间得到一个无限重定向。重定向操作如下所示: http://localhost:8080/ http://localhost:8080/login https://auth.example.com/oauth/author

我正在努力将使用OAuth和自定义授权服务器的应用程序从SpringBoot1.5升级到SpringBoot2

OAuth流使用auth服务器及其spring boot 1.5设置正常运行。但是,在当前迁移到SpringBoot2.1.3之后

我在auth服务器和客户机应用程序之间得到一个无限重定向。重定向操作如下所示:

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]
...
如您所见,一旦auth服务器使用查询字符串上的auth代码重定向回登录,客户端应用程序就会重定向回/login重新启动整个过程,然后无限重定向,直到浏览器调用stop

我已将应用程序剥离到最底层,以下是我的配置:

application.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


我已经找到了问题的解决方案,结果是Spring Boot 2在请求访问令牌时似乎没有默认使用授权头,添加以下config属性解决了问题

security:
  oauth2:
    client:
      authenticationScheme: header