首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring-Security-Oauth2:需要完全身份验证才能访问此资源

Spring-Security-Oauth2:需要完全身份验证才能访问此资源
EN

Stack Overflow用户
提问于 2014-11-12 15:17:02
回答 8查看 167.2K关注 0票数 46

我正在尝试使用基于Java的配置的spring-security-oauth2.0。我的配置已经完成,但是当我在tomcat上部署应用程序并点击访问令牌的/oauth/token url时,Oauth生成了以下错误:

代码语言:javascript
复制
<oauth>
<error_description>Full authentication is required to access this resource</error_description>
<error>unauthorized</error>
</oauth>

我的配置在Git hub, please click on link

代码很大,所以请参考git。我正在使用chrome postman客户端发送请求。以下是我的请求。

代码语言:javascript
复制
POST /dummy-project-web/oauth/token HTTP/1.1
Host: localhost:8081
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&client_id=abc%40gmail.com&client_secret=12345678 

错误就像,URL是由Oauth保护的,但是在配置中,我给了all访问这个URL的权限。这个问题到底是什么?

EN

回答 8

Stack Overflow用户

发布于 2014-11-12 18:10:47

默认情况下,client_idclient_secret应该放在Authorization头中,而不是form- and编码的正文中。

使用冒号连接您的client_idclient_secretYWJjQGdtYWlsLmNvbToxMjM0NTY3OA==

  • Set 64 encode
  1. result:Authorization: Basic YWJjQGdtYWlsLmNvbToxMjM0NTY3OA==

  1. header:Authorization: Basic YWJjQGdtYWlsLmNvbToxMjM0NTY3OA==
票数 26
EN

Stack Overflow用户

发布于 2015-10-23 03:38:13

默认情况下,Spring需要基本的OAuth身份验证。如果您想在基于Java的配置中将其关闭,则必须允许对客户端进行表单身份验证,如下所示:

代码语言:javascript
复制
@Configuration
@EnableAuthorizationServer
protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {
  @Override
  public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
    oauthServer.allowFormAuthenticationForClients();
  }
}
票数 19
EN

Stack Overflow用户

发布于 2014-11-14 04:02:24

原因是,默认情况下,通过Basic Access Authentication保护/oauth/token端点。

您需要做的就是将Authorization头添加到您的请求中。

您可以使用像curl这样的工具轻松地测试它,只需发出以下命令:

curl.exe --user abc@gmail.com:12345678 http://localhost:8081/dummy-project-web/oauth/token?grant_type=client_credentials

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26881296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档