ZPY博客

Spring Security Oauth2.0报错User must be authenticated with Spring Security before authorization can be completed

今天访问http://localhost:8081/auth/oauth/authorize?时居然报错了,但前几天还是好的啊

User must be authenticated with Spring Security before authorization can be completed

想起这两天为了跨域的问题改了点代码,所以把有几个地方修改的代码逐一注释来排查。最后发现是HttpMethod.OPTIONS这个的影响。

有问题的代码:

http.requestMatchers()
               .antMatchers(HttpMethod.OPTIONS, "/login", "/oauth/authorize", "/oauth/token")

修改后的代码

http.requestMatchers()
               .antMatchers("/login", "/oauth/authorize", "/oauth/token")

到此,问题解决。