spring - POST 请求 "Full authentication is required to access this resource"

标签 spring authentication spring-boot oauth-2.0

是否有人在尝试使用 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/

相关文章:

redirect - Prestashop 无法登录管理员

javascript - 如何使用 Node js 中的 API key 从 REST api 获取数据?

java - 使用 Jackson 解码和反序列化其值为 Base64 编码、字符串化 JSON blob 的字段的最简单方法

java - 使用 Lombok 进行 Spring Boot 日志记录

java - 如何将 POJO 添加到 Spring 上下文以启用注入(inject)依赖项?

java - Spring 的上下文命名空间是如何工作的?

java - Spring - 为请求 header 名称注入(inject)值

java - Spring 的多重依赖

javascript - Koa Auth 流程与 compose

java - 收到的数据比预期多