我正在尝试使用基于Java的配置的spring-security-oauth2.0。我的配置已经完成,但是当我在tomcat上部署应用程序并点击访问令牌的/oauth/token url时,Oauth生成了以下错误:
<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客户端发送请求。以下是我的请求。
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的权限。这个问题到底是什么?
发布于 2014-11-12 18:10:47
默认情况下,client_id和client_secret应该放在Authorization头中,而不是form- and编码的正文中。
使用冒号连接您的client_id和client_secret:YWJjQGdtYWlsLmNvbToxMjM0NTY3OA==
Authorization: Basic YWJjQGdtYWlsLmNvbToxMjM0NTY3OA==
Authorization: Basic YWJjQGdtYWlsLmNvbToxMjM0NTY3OA==发布于 2015-10-23 03:38:13
默认情况下,Spring需要基本的OAuth身份验证。如果您想在基于Java的配置中将其关闭,则必须允许对客户端进行表单身份验证,如下所示:
@Configuration
@EnableAuthorizationServer
protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.allowFormAuthenticationForClients();
}
}发布于 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
https://stackoverflow.com/questions/26881296
复制相似问题