Spring Security Oauth2.0报错localhost将您的重定向次数过多

  • A+
所属分类:Spring Security

Spring Security Oauth2.0访问/oauth/authorize认证完成后返回到redirect_uri时报错localhost将您的重定向次数过多

debug看了下,出现这个问题是因为会无限重定向到这个redirect_uri。

但是为什么会无限重定向到这个地址呢?最终尝试了很多才弄懂。

首先,访问/oauth/authorize,认证成功会返回到redirect_uri并带上一个授权码code和state。但是这个时候请注意,如果在configure里没有添加例外,只有code还是进不了这个回调的页面的,所以他只能再次认证,变成死循环

所以最终的解决方法是,在WebSecurityConfigurerAdapter的configure里添加redirect_uri的地址,让它在没有认证时也能访问即可。

比如我这里的redirect_uri是http://localhost:8082/ui/hehe

所以代码如下 :

        http.antMatcher("/**")
                .authorizeRequests()
                .antMatchers("/","/test**","/index**","/hehe**","/login**")
//                .anyRequest()
                .permitAll()
                .anyRequest()
                .authenticated();

 

ZPY

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: