Har*_*ara 30 java unauthorized oauth-2.0 spring-security-oauth2
我正在尝试使用spring-security-oauth2.0
基于Java的配置.我的配置已完成,但是当我在tomcat上部署应用程序并点击/oauth/token
访问令牌的url时,会Oauth
生成以下错误:
<oauth>
<error_description>Full authentication is required to access this resource</error_description>
<error>unauthorized</error>
</oauth>
Run Code Online (Sandbox Code Playgroud)
我的配置在Git中心,请点击链接
代码很大,所以请参考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
Run Code Online (Sandbox Code Playgroud)
错误就像,URL是安全的Oauth
,但在配置中,我给予访问此URL的所有权限.这个问题究竟是什么?
Gar*_*ryF 22
该client_id
和client_secret
,默认情况下,应该在Authorization头,而不是窗体-urlencoded体.
client_id
和client_secret
它们之间的冒号:abc@gmail.com:12345678
.YWJjQGdtYWlsLmNvbToxMjM0NTY3OA==
Authorization: Basic YWJjQGdtYWlsLmNvbToxMjM0NTY3OA==
man*_*ekq 17
默认情况下,Spring OAuth需要基本的HTTP身份验证.如果要使用基于Java的配置将其关闭,则必须允许客户端的表单身份验证,如下所示:
@Configuration
@EnableAuthorizationServer
protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.allowFormAuthenticationForClients();
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
原因是默认情况下/oauth/token
端点通过基本访问身份验证进行保护.
您需要做的就是将Authorization
标题添加到您的请求中.
您可以使用类似于curl
发出以下命令的工具轻松测试它:
curl.exe --user abc@gmail.com:12345678 http://localhost:8081/dummy-project-web/oauth/token?grant_type=client_credentials
归档时间: |
|
查看次数: |
99456 次 |
最近记录: |