【问题标题】:Get the user role from Azure AD by Laravel azure ad oauth通过 Laravel azure ad oauth 从 Azure AD 获取用户角色
【发布时间】:2020-02-19 06:10:30
【问题描述】:

我正在尝试通过使用 metrogistics/laravel-azure-ad-oauth socialiate 插件从 Azure AD 中获取角色。

我从 Azure 获得了姓名、电子邮件和 azure_id。但我无法获取用户角色。

user: array:12 [
    "@odata.context" => "https://graph.microsoft.com/v1.0/$metadata#users/$entity"
    "businessPhones" => []
    "displayName" => "Test4"
    "givenName" => "Test4"
    "jobTitle" => null
    "mail" => null
    "mobilePhone" => null
    "officeLocation" => null
    "preferredLanguage" => null
    "surname" => null
    "userPrincipalName" => "test4@xyz.com"
    "id" => "xyz"
  ]

可以从 Azure 获取角色。 我的设置:

image1image2image3

【问题讨论】:

  • 请问您的“角色”是什么意思?
  • 我在 Azure 门户中创建了客户组和角色,例如 BDO、BDA。并在组和角色下分配员工。我尝试在登录时得到那个

标签: php laravel azure oauth azure-active-directory


【解决方案1】:

您拥有的是app role,顾名思义,它们属于一个应用程序。仅仅从 Microsoft Graph 中寻找用户的对象并不能提供这些。

是的,如另一个答案所示,它们将在用户登录后以 id_token 的形式提供给应用程序。

要独立于应用获取这些内容,请使用 Get appRoleAssignment Api。

【讨论】:

  • 它是测试版。它在生产 URL 中是否可以通过。 (graph.microsoft.com/v1.0)
  • 还没有,所有 /beta API 最终会在几个月后投入生产
【解决方案2】:

根据我的研究,定义的 AppRole 会在 id_token 中返回。更多详情请参考official documentationdocument

关于如何获取用户的id token,可以使用Azure ADOAuth 2.0 authorization code flow来实现。这里我使用postman来获取access_token和id_token:

然后我可以得到 id_token

通过分析id token,可以得到用户的角色:


更新

关于如何为用户分配应用角色,请参考以下步骤

  1. 声明应用角色

  2. 为用户分配角色

    一个。在 Azure Active Directory 窗格中,从 Azure Active Directory 左侧导航菜单中选择 Enterprise applications

    b.选择所有应用程序以查看所有应用程序的列表。如果您没有在此处看到要显示的应用程序,请使用所有应用程序列表顶部的各种过滤器来限制列表或向下滚动列表以找到您的应用程序。

    c。分配角色

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-03
  • 1970-01-01
  • 2015-04-14
  • 2019-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多