首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Boot 2 Oauth无限重定向

Spring Boot 2 Oauth无限重定向
EN

Stack Overflow用户
提问于 2019-06-28 16:51:32
回答 1查看 195关注 0票数 0

我正在努力将一个应用程序从Spring Boot1.5升级到使用OAuth和自定义授权服务器的Spring Boot2。

使用身份验证服务器和spring Boot1.5设置时,OAuth流可以正常工作。然而,在迁移到spring Boot2(目前是2.1.3)之后。

我得到了身份验证服务器和客户端应用程序之间的无限重定向。重定向的过程如下:

代码语言:javascript
复制
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

代码语言:javascript
复制
@SpringBootApplication
public class Application
{

   public static void main( String[] args )
   {
      SpringApplication.run( AdminApplication.class, args );
   }

}

SecurityConfig.java

代码语言:javascript
复制
@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

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2019-06-28 17:58:45

我已经找到了问题的解决方案,原来Spring Boot2在请求访问令牌时似乎没有默认使用Authorization头,添加了以下配置属性解决了这个问题

代码语言:javascript
复制
security:
  oauth2:
    client:
      authenticationScheme: header
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56803785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档