【问题标题】:How to make scope in Symfony Oauth 2.0?如何在 Symfony Oauth 2.0 中创建范围?
【发布时间】:2018-11-15 17:59:26
【问题描述】:

我以http://blog.tankist.de/ 为例开发了oauth 2.0 登录。但我无法决定范围。你能帮帮我吗?

【问题讨论】:

  • 范围由资源服务器定义。您应该检查资源服务器的文档以了解可用的范围。
  • OP 正在实施 OAuth 服务器。检查他发布的链接。 blog.tankist.de 描述了设置 FOSOAuthServerBundle。

标签: symfony scope oauth-2.0


【解决方案1】:

这里有很好的记录:https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/blob/master/Resources/doc/dealing_with_scopes.md

要在您的应用程序中配置允许的范围,您必须编辑您的 app/config/config.yml 文件:

fos_oauth_server:
    service:
        options:
            supported_scopes: scope1 scope2

FOSOAuthServerBundle 的默认行为是将作用域用作角色。在前面的示例中,它允许我们使用角色 ROLE_SCOPE1 和 ROLE_SCOPE2(范围自动大写)。

你可以在你的控制器中这样检查

// symfony 2.6
$this->get('security.authorization_checker')->isGranted('ROLE_SCOPE1')

// symfony < 2.6
$this->get('security.context')->isGranted('ROLE_SCOPE1')

【讨论】:

  • 谁能解释为什么这被否决了? OP 正在实施 OAuth 服务器。检查他发布的链接。 blog.tankist.de 描述了设置 FOSOAuthServerBundle。
  • 我看到了这些。但我不明白, $this->get('security.authorization_checker')->isGranted('ROLE_SCOPE1') 不起作用。如何编写security.yml
  • 您请求了一个不存在的服务“security.authorization_checker”。您的意思是:“security.authentication.manager”?
  • 你用的是什么symfony版本?
  • 2.5 是我的 symfony 版本
猜你喜欢
  • 2017-05-28
  • 1970-01-01
  • 1970-01-01
  • 2020-11-21
  • 2020-06-19
  • 1970-01-01
  • 1970-01-01
  • 2020-12-30
  • 2020-10-05
相关资源
最近更新 更多