AAD 颁发的 JWT 令牌中缺少角色声明

ami*_*vas 5 active-directory azure

我正在使用 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"
        }
    ],
    
    Run Code Online (Sandbox Code Playgroud)
  5. 资源服务器服务主体创建

  6. 为客户端应用程序分配角色。

当我尝试使用客户端应用程序的凭据获取访问令牌时,我没有在 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 中定义为 Role。

通过门户从 Resource_API_11092017 授予权限。

ami*_*vas 2

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

  1. 创建客户端应用程序。
  2. 创建客户端应用程序的服务主体。
  3. 创建资源应用程序,其角色定义为:
"appRoles": [{
    "allowedMemberTypes": [
      "Application"
    ],
Run Code Online (Sandbox Code Playgroud)
  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"
}
Run Code Online (Sandbox Code Playgroud)