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

时间:2017-02-11 21:14:23

标签: spring authentication spring-boot oauth-2.0

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

卷曲命令:

curl localhost:85/oauth/token -d grant_type=password -d client_id=web_app -d username=reader -d password=reader

响应:

{"timestamp":1486841819620,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource","path":"/oauth/token"}

ResourceServerConfiguration configure

http .csrf().disable() .authorizeRequests() .antMatchers("/**").authenticated() .antMatchers(HttpMethod.GET, "/me").hasAuthority("FOO_READ")

WebSecurityConfig configure

http .csrf().disable() .exceptionHandling() .authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED))

谢谢!

2 个答案:

答案 0 :(得分:0)

上述答案的其他详细信息。

例如base64编码your_client_id:your_client_secret ==> eW91cl9jbGllbnRfaWQ6eW91cl9jbGllbnRfc2VjcmV0

卷曲命令:

curl localhost:85 / oauth / token -d grant_type =密码-d client_id = web_app -d用户名=读者-d密码=读者-H'授权:基本eW91cl9jbGllbnRfaWQ6eW91cl9jbGllbnRfc2VjcmV0'

答案 1 :(得分:0)

此错误消息来自您自己的后端服务器。这是一个Spring框架错误。如果使用2个提供程序进行检查,则可以看到错误消息对于两个提供商都是相同的。就我而言,问题的根源是我作为回调URL的错误映射。我将服务器配置为允许到达端点localhost:8080/oauth2/callback/**的所有请求都无需身份验证即可通过,而来自提供程序的回调被配置为localhost:8080/login/oauth2/**。我在this教程之后犯了这个错误。由于任何原因,如果这些配置之间不匹配,您将得到错误。