【问题标题】:Missing role claims in JWT Token issued by AADAAD 发布的 JWT 令牌中缺少角色声明
【发布时间】:2017-11-13 22:25:09
【问题描述】:

我正在使用 Micrsoft Graph API 以编程方式注册客户端应用程序、资源服务器并将角色从资源服务器分配给客户端应用程序。以下是遵循的步骤:

  1. 获取访问令牌 --> https://login.windows.net//oauth2/token/?api-version=1.6

  2. 客户端应用注册 --> https://graph.windows.net//applications/?api-version=1.6

  3. 客户服务负责人

  4. 清单中具有以下应用角色的资源服务器注册:

"appRoles": [
  {
    "allowedMemberTypes": [
      "Application"
    ],
    "description": "Description of Role - Resource_API_11092017",
    "displayName": "Role_Resource_API_11092017",
    "id": "5ff0033d-fa87-4a77-9b3d-b4b201dfc32e",
    "isEnabled": true,
    "value": "Read_Only_Resource_API_11092017"
  }
],
  1. 资源服务器服务主体创建

  2. 为客户端应用分配角色。

当我尝试使用客户端应用程序的凭据获取访问令牌时,我没有获得 JWT 中的任何角色,也没有获得资源服务器的任何信息。

我什至从客户端应用程序中的门户授予资源服务器角色的权限。但仍然没有运气。

任何帮助将不胜感激。如果您需要更多详细信息,请告诉我。

谢谢。

@2017 年 11 月 14 日更新:

请找到 JWT 的 Payload。

{
  "aud": "https://xxxxx.onmicrosoft.com/Resource_API_11092017",
  "iss": "https://sts.windows.net/caa4bd37-xxxx-xxxx-xxxx-bba4bd0e22a6/",
  "iat": 1510679930,
  "nbf": 1510679930,
  "exp": 1510683830,
  "aio": "Y2NgYLipff1Ghn65atEd97grbjxxxx==",
  "appid": "3ec8690d-xxxx-xxxx-xxxx-739709a758cc",
  "appidacr": "1",
  "idp": "https://sts.windows.net/caa4bd37-xxxx-xxxx-xxxx-bba4bd0e22a6/",
  "tid": "caa4bd37-xxxx-xxxx-xxxx-bba4bd0e22a6",
  "ver": "1.0"
}

服务主体中不包含任何角色。但我已使用门户将 Role_Assigned_API_11092017 分配为应用程序权限。这个 Role_Assigned_API_11092017 被定义为资源应用 Resource_API_11092017 中的角色。

权限是通过门户从 Resource_API_11092017 授予的。

【问题讨论】:

  • 嗨。你要回什么信息?你有任何索赔吗?你解码后的 JWT 是什么样子的?
  • 您可以使用 Graph Explorer 检查您的 appRoleAssignments。你的客户端应用的服务主体应该有它们,所以试试https://graph.windows.net/tenant-id/servicePrincipals/client-sp-id/appRoleAssignments
  • 当您按授予权限时应该创建这些分配。
  • @UsmanMutawakil,感谢您的回复。请在下面找到示例 JWT。
  • @juunas,请更新我的答案。

标签: azure active-directory


【解决方案1】:

我能够在令牌中获得角色声明。如果您希望客户端应用在资源应用中定义角色,则需要遵循以下步骤。

  1. 创建客户端应用程序。
  2. 创建客户端应用的服务主体。
  3. 创建资源应用,其角色定义为:
"appRoles": [{
    "allowedMemberTypes": [
      "Application"
    ],
  1. 为资源应用创建服务主体。
  2. 使用资源应用中定义的角色修补客户端应用和资源应用。 - 在客户端应用的所需权限部分允许角色
  3. 授予客户端应用程序登录权限,通过您的管理员帐户从 azure 门户 ` 除了第 6 步之外,一切都可以使用 Microsoft Graph API 使用具有足够权限的应用程序的访问令牌来完成,以便在您的目录中注册应用程序。

如果有人从客户端应用程序获得了相应的授予权限操作 API。请告诉我。目前,我们正在采取手动步骤。
谢谢。

{
  "aud": "https://xxxxxxx.onmicrosoft.com/resource_app_11202017",
  "iss": "https://sts.windows.net/caa4bd37-xxxx-xxxx-xxxx-bba4bdxxxxa6/",
  "iat": 1511209576,
  "nbf": 1511209576,
  "exp": 1511213476,
  "aio": "Y2xxxxBlVE3nxxxxHtx3xSxxxxLAQ==",
  "appid": "dffe69ef-xxxx-xxxx-xxxx-3550bxxxxbd7",
  "appidacr": "1",
  "idp": "https://sts.windows.net/caa4bd37-xxxx-xxxx-xxxx-bba4bdxxxxa6/",
  "oid": "f2af0608-xxxx-xxxx-xxxx-a5acacxxxx8d",
  "roles": [
    "readonly_role_resource_app_11202017",
    "writeonly_role_resource_app_11202017"
  ],
  "sub": "f2af0608-xxxx-xxxx-xxxx-a5acacxxxx8d",
  "tid": "caa4bd37-xxxx-xxxx-xxxx-bba4bdxxxxa6",
  "uti": "VW6inKHUI0SgkuNMi6AcAA",
  "ver": "1.0"
}

【讨论】:

    猜你喜欢
    • 2019-01-24
    • 1970-01-01
    • 2020-02-13
    • 2018-02-07
    • 2020-11-10
    • 2021-04-21
    • 2020-01-03
    • 2023-03-31
    • 2020-11-05
    相关资源
    最近更新 更多