POST请求"访问此资源需要完全身份验证"

0x5*_*539 8 authentication spring oauth-2.0 spring-boot

是否有人遇到错误"访问此资源需要完全身份验证"尝试使用POST请求oauth/token进行身份验证?

卷曲命令:

curl localhost:85/oauth/token -d grant_type=password -d client_id=web_app -d username=reader -d password=reader
Run Code Online (Sandbox Code Playgroud)

响应:

{"timestamp":1486841819620,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource","path":"/oauth/token"}
Run Code Online (Sandbox Code Playgroud)

ResourceServerConfiguration配置

http .csrf().disable() .authorizeRequests() .antMatchers("/**").authenticated() .antMatchers(HttpMethod.GET, "/me").hasAuthority("FOO_READ")
Run Code Online (Sandbox Code Playgroud)

WebSecurityConfig配置

http .csrf().disable() .exceptionHandling() .authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED))
Run Code Online (Sandbox Code Playgroud)

谢谢!

Dej*_*ach 1

此错误消息来自您自己的后端服务器。这是一个spring框架错误。如果您检查 2 个提供商,您会发现两者的错误消息是相同的。就我而言,问题的根源在于我将错误的映射作为回调 URL。我将服务器配置为允许所有到达端点的请求localhost:8080/oauth2/callback/**无需身份验证即可通过,而来自提供程序的回调则配置为localhost:8080/login/oauth2/**. 我按照教程犯了这个错误。无论出于何种原因,如果这些配置之间存在不匹配,您都会收到错误消息。