【问题标题】:POST request "Full authentication is required to access this resource"POST 请求“访问此资源需要完全身份验证”
【发布时间】:2017-06-30 02:18:50
【问题描述】:

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

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))

谢谢!

【问题讨论】:

  • 您作为客户端,需要使用 HTTP 基本身份验证向授权服务器进行身份验证
  • Authorization: Basic base64(client_id:client_secret)
  • 您解决了这个问题吗?

标签: spring authentication spring-boot oauth-2.0


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-03-30
    • 2016-10-03
    • 2016-11-11
    • 2015-01-08
    • 2018-09-11
    • 2019-01-01
    • 2020-11-21
    • 2016-07-21
    • 2022-01-03
    相关资源
    最近更新 更多