在Spring Security Oauth2版本2.0.7.RELEASE中请求多个作用域

Kar*_*hik 3 java spring spring-security spring-security-oauth2

我们有一个正在使用的应用程序spring-security-oauth2:1.0.我试图将其更改为更新版本spring-security-oauth2:2.0.7.RELEASE.如果我没有指定scope或如果我指定我单一范围,应用程序工作正常.我在请求多个范围时遇到问题,这些范围read,write曾经在以前的版本中工作过.

我请求的客户端拥有所有read,write and trust权限.

当我使用时spring-security-oauth2:1.0,为了得到一个令牌我曾经做过像这样的来电

HTTP://本地主机:8080 /的OAuth /令牌grant_type =密码&CLIENT_ID = WS&client_secret =秘密及范围=读,写和用户名=用户名@ abc.com和密码= temp123

如果您看到scope参数scope=read,write,通过请求这种方式,我曾经获得一个带范围的令牌read and write.

如果我尝试使用Oauth2版本做同样的事情2.0.7.RELEASE(POST尽管有请求),我会得到Invalid Scope例外,因为它tokenRequestread,write作为单个范围.我请求的客户端具有read,write and trust权限,但read,write不是其中之一.

如果我尝试使用scope=writescope=read,它工作正常,因为read或是write客户范围的一部分.

如果我想申请多个范围OAuth2 2.0.7.RELEASE,我该怎么做?

Kar*_*hik 5

我找到了正确的方法来做到这一点.您必须使用+分隔范围而不是逗号分隔的范围.

例如:read+write,write+trust

所以以下POST请求工作正常.

http:// localhost:8080/oauth/token?grant_type = password&client_id = ws&client_secret = secret&scope = read + write &username=user@abc.com&password=temp123

我希望它会帮助别人:)

  • 不,在数据库中你应该有 **read,write,trust** 并且在请求时你应该有 - **scope=read+write+trust** (2认同)