是否有人在尝试使用 POST 请求 oauth/token 进行身份验证时遇到错误“访问此资源需要完全身份验证”?
curl 命令:
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配置
http .csrf().disable() .authorizeRequests() .antMatchers("/**").authenticated() .antMatchers(HttpMethod.GET, "/me").hasAuthority("FOO_READ")
WebSecurityConfig配置
http .csrf().disable() .exceptionHandling() .authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED))
谢谢!
最佳答案
此错误消息来自您自己的后端服务器。这是一个spring框架错误。如果您检查 2 个提供商,您会发现两者的错误消息是相同的。就我而言,问题的根源在于我将错误的映射作为回调 URL。我将服务器配置为允许所有到达端点 localhost:8080/oauth2/callback/**
的请求当来自提供商的回调配置为 localhost:8080/login/oauth2/**
时无需身份验证即可通过。我在 this 之后犯了这个错误教程。无论出于何种原因,如果这些配置之间存在不匹配,您都会收到错误。
关于spring - POST 请求 "Full authentication is required to access this resource",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42181318/