【问题标题】:Azure AD does not emit group claimsAzure AD 不发出组声明
【发布时间】:2017-03-14 15:10:58
【问题描述】:

我正在尝试通过组为我在 azure 上的应用程序设置基于角色的访问权限。我关注了以下文章(抱歉将链接作为代码发布,不允许发布超过 1 个链接)。但是我的应用没有收到任何群组声明。

https://www.simple-talk.com/cloud/security-and-compliance/azure-active-directory-part-4-group-claims/

http://www.dushyantgill.com/blog/2014/12/10/roles-based-access-control-in-cloud-applications-using-azure-ad/

到目前为止我做了什么

清单文件

    "appId": "d754a979-689d-45f8-8c63-983de55840da"
"appRoles": [
    {
      "allowedMemberTypes": [
        "User"
      ],
      "displayName": "Manager",
      "id": "1e06dae5-467a-40cf-a9a6-14baf3969472",
      "isEnabled": true,
      "description": "Manages",
      "value": "Manager"
    },
    {
      "allowedMemberTypes": [
        "User"
      ],
      "displayName": "Issuer",
      "id": "da85f458-720d-4c09-861f-92f5c465ee3e",
      "isEnabled": true,
      "description": "Issues",
      "value": "Issuer"
    },
    {
      "allowedMemberTypes": [
        "User"
      ],
      "displayName": "Supervisor",
      "id": "d64807d4-6e12-4637-a049-2a61b250507b",
      "isEnabled": true,
      "description": "Can perform any function",
      "value": "Supervisor"
    }
  ],
  "availableToOtherTenants": false,
  "displayName": "traffic",
  "errorUrl": null,
  "groupMembershipClaims": "SecurityGroup",
  "homepage": "https://myapp.ca",
  "identifierUris": [
    "https://myapp.azurewebsites.net/"
  ],

还在 azure 上的应用中添加了相关组(假设该组至少包含一个用户) Groups Assignment on Azure

但我的应用中没有收到任何群组声明。以下代码始终导致计数为零。有任何想法吗?提前致谢。

var claims = ClaimsPrincipal.Current.Claims.Where(c => c.Type == "groups");

            Debug.Print("Total Group Claims in HomeController #### "+claims.Count());

            foreach (Claim c in claims)
            {
                Debug.Print("%%%%%%%% " + c.Value + " %%% VALUETYPE %%% " + c.Type);
            }

【问题讨论】:

    标签: .net azure active-directory


    【解决方案1】:

    问题解决了。我在咆哮错误的应用程序配置文件。我的 AD 注册了许多应用程序(沙盒、测试等)。原来我编辑了错误的个人资料。我在问题中提到的步骤确实有效。感谢@Fei Xue - MSFT 的时间和帮助。

    【讨论】:

      【解决方案2】:

      我在这里遇到的另一个问题是老问题:耐心!

      将 Manifest 中的 groupMembershipClaims 从 null 更改为 SecurityGroup 后,您需要等待它.. 有时长达一个小时。我以为我错过了权限等等,但只要登录的用户有权从 AD 读取组(他们通常这样做),就不需要额外的权限。

      所以要获得组授权以使用 Azure AD:

      1. 打开视觉工作室
      2. 创建一个新的网络应用程序
      3. 选择身份验证 - 选择工作或学校帐户(离开读取目录 空白)
      4. 转到 Azure AD 中的新应用 -> 应用注册和 将 Manifest 文件中的 groupMembershipClaims 更改为 SecurityGroup 并保存。
      5. 等待至少一个小时。
      6. 测试您是否获得组 通过将其放入索引文件中声明:

      <table class="table">
          @foreach (var claim in User.Claims)
          {
              <tr>
                  <td>@claim.Type</td>
                  <td>@claim.Value</td>
              </tr>
          }
          </table>

      【讨论】:

        【解决方案3】:

        由于您在应用程序的清单中指定了SecurityGroup,Azure AD 仅发出此类类型组声明。您可以将SecurityGroup 更改为All 以使Azure AD 发出各种组声明。

        还要确保用户是少于 150 个组的成员,因为组数有限制(请参阅 here)。

        并确保已为登录 Web 应用的用户分配了组。您可以参考代码示例active-directory-dotnet-webapp-groupclaims 来显示群组声明。

        【讨论】:

        • 谢谢飞雪。已经尝试并验证了所有这些步骤。不起作用 :( 不确定我是否遗漏了什么......自从我将我的应用程序部署到 Azure 后是否涉及任何其他步骤。
        • 部署到 Azure 不会影响此行为。并且没有其他额外的步骤可以在 id_token 中发出组声明。我建议您关注active-directory-dotnet-webapp-groupclaims 从头开始​​测试它应该可以正常工作。
        【解决方案4】:

        我遇到了类似的问题,即未将组作为索赔退回。

        为了解决这个问题,我做了两件事:

        • 在 Azure AD、App Registrations、[用于访问 AD 的 app reg]、Token Configuration 下,有一个按钮:“Add groups claim”。我勾选了所有的方框。我可以确认这一步是必要的。

        • 在同一屏幕中,左侧菜单还具有“API 权限”。最初我只有“User.Read”。我有“User.ReadAll”、“Directory.Read”和“Directory.ReadAll”。我在其他步骤之前已经这样做了,所以我不确定是否有必要。

        【讨论】:

          猜你喜欢
          • 2019-03-04
          • 1970-01-01
          • 1970-01-01
          • 2020-12-23
          • 2016-02-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-03-03
          相关资源
          最近更新 更多