【发布时间】:2016-01-13 18:02:36
【问题描述】:
我有一个使用 FOSOAuthServerBundle 对用户进行身份验证的基本 api。用户可以具有 ROLE_USER 和 ROLE_ADMIN 角色。基于 FOSOAuthServerBundle 文档,默认行为是使用作用域作为角色,所以我认为当我有普通用户时,捆绑包会在响应中返回 scope: user,当它是管理员用户时,会返回 @987654322 @。但它不是这样工作的。捆绑包返回supported_scopesentry 中配置的任何内容。下面是我的config.yml。
fos_oauth_server:
service:
options:
supported_scopes: user admin
security.yml 中我的access_control 部分为空,而我的firewalls 部分如下:
firewalls:
users_create:
pattern: ^/v1/users
methods: [POST]
security: false
api:
pattern: ^/
security: true
fos_oauth: true
stateless: true
access_control:
# You can omit this if /api can be accessed both authenticated and anonymously
这样,即使用户没有 ROLE_ADMIN 角色,捆绑包总是返回 user admin 作为范围。
{
"access_token": "ZGQ2ODE5ZjAzNTZkOWY0OWMyNmZmODE4MjcwZTJmYjExNzY0NzQxOTRmMzk4NzA2Mjc2NjIyZmY1ZDgwMzk4NA"
"expires_in": 3600
"token_type": "bearer"
"scope": "user admin"
"refresh_token": "NmM5ZGFmNzBiNTNjYmQzMTQ1MTk0ODJjOTAxMWU0YWIwMzM1MzgyODg4ZTAzNTI5ZTk2MDc3OGU2MTg0MWZiMA"
}
我错过了什么?用户角色不是附加到令牌范围吗?有没有更好的方法来知道我的用户是否是管理员?
【问题讨论】:
-
可能不是你的
security.yml而是从config.yml粘贴的?您能提供access_control:部分的security.yml吗? -
你说得对,伊莉雅。编辑我的问题。
标签: php symfony oauth fosoauthserverbundle