Spring security Oauth2 资源所有者密码凭据授予

标签 spring security oauth passwords

刚刚在我的 Eclipse IDE 中安装了 spring security oauth2。我尝试实现的服务将由第二方用户通过他们安装的应用程序使用,因此我选择使用密码授予类型。根据我对 Oauth2 的理解,以下请求应该适用于演示 sparklr2 服务,而无需我输入用户名和密码参数。 IE

POST http://localhost:8080/sparklr2/oauth/token?grant_type=password&client_id=my-trusted-client&scope=trust&username=marissa&password=koala

但我不断得到
<oauth>
<error_description>
Full authentication is required to access this resource
</error_description>
<error>unauthorized</error>
</oauth>

我是否在此请求中遗漏了某些内容,或者我是否需要在 repo 中启用某些内容

最佳答案

似乎 Spring OAuth2 不支持无 secret OAuth2 客户端的密码授予类型。这可能符合 OAuth2 规范: http://tools.ietf.org/html/rfc6749#section-4.3.2 ,尽管规范似乎表明并不总是需要客户端身份验证(这对我来说不是很清楚)。

这意味着在使用密码授权类型调用 token 端点时,您需要传入客户端 ID 和密码(使用基本身份验证),这也意味着如果客户端没有密码,您将无法使用密码授权(您可能仍然可以使用隐式流程)。

在 sparklr2 中,my-trusted-client 没有定义 secret ,这就是调用失败的原因。

如果您想查看密码授予类型的实际效果,可以尝试 my-trusted-client-with-secret :

curl -u my-trusted-client-with-secret:somesecret "http://localhost:8080/sparklr2/oauth/token?grant_type=password&username=marissa&password=koala"

关于Spring security Oauth2 资源所有者密码凭据授予,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24699978/

相关文章:

javascript - Google OAuth 按钮不起作用

java - 在 Jetty 中生成用户线程

Java Spring Thymeleaf 下拉列表被禁用并出现

security - 用于存储 secret 的可移植数据库

php - 如何防止 PHP 中的 SQL 注入(inject)?

asp.net - AJAX 和 asp.net 安全问题

asp.net-mvc - 在 MVC API 中使用 Microsoft Azure Active Directory 验证 OAuth 2.0 不记名 token 时出现 401

oauth - child 在 OAuth 2.0 流程上不匹配

spring - 是否可以拆分 ehcache 配置文件?

spring - org.apache.kafka.common.errors.RecordTooLargeException : The request included a message larger than the max message size the server will accept 错误