【问题标题】:Requesting multiple scopes in Spring Security Oauth2 version 2.0.7.RELEASE在 Spring Security Oauth2 版本 2.0.7.RELEASE 中请求多个范围
【发布时间】:2015-10-11 10:11:40
【问题描述】:

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

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

当我使用spring-security-oauth2:1.0 时,为了获取令牌,我曾经使用 get 调用类似

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

如果您看到范围参数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,它会正常工作,因为readwrite 是客户端范围的一部分。

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

【问题讨论】:

    标签: java spring spring-security spring-security-oauth2


    【解决方案1】:

    我找到了正确的方法。您必须使用+ 来分隔范围,而不是逗号分隔的范围。

    例如:read+writewrite+trust

    所以下面的POST 请求运行良好。

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

    我希望它会帮助其他人:)

    【讨论】:

    • 如果我对客户有读、写、信任的作用域,我该怎么写?请回复
    • 它不适合我..我想在数据库中写范围也这样吗??
    • 是的,在数据​​库中,您应该允许该客户端的范围。
    • 我想在数据库中将范围写为读+写+信任吗??
    • 不,在数据库中你应该有 read,write,trust 并且在请求时你应该有 - scope=read+write+trust跨度>
    猜你喜欢
    • 1970-01-01
    • 2012-07-14
    • 2020-11-25
    • 2017-01-08
    • 2017-06-26
    • 2019-01-03
    • 2016-07-19
    • 2020-05-11
    • 2014-11-05
    相关资源
    最近更新 更多