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

时间:2017-11-13 22:25:10

标签: azure active-directory

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

  1. 获取访问令牌 - > https://login.windows.net/ /的oauth2 /令牌/?API-版本= 1.6

  2. 客户端应用注册 - > https://graph.windows.net/ /应用/?API-版本= 1.6

  3. 客户服务负责人

  4. 在清单中使用以下app角色注册资源服务器:

    "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"
        }
    ],
    
  5. 资源服务器服务主体创建

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

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

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

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

    感谢。

    @Update on 11/14/2017:

    请查找JWT的有效载荷。

    { "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通过Portal授予。

1 个答案:

答案 0 :(得分:0)

我能够在令牌中获得角色声明。如果您希望客户端应用程序在资源应用程序中定义角色,则需要执行以下步骤 1. Create client App. 2. Create service principal of the client app. 3. Create resource app with roles defined as "appRoles": [{ "allowedMemberTypes": [ "Application" ], 4.Create service principal for the resource app. 5. Patch the client app and resource app with the roles defined in the resource app. - Allow Roles in the Required Permission section of the client app 6. Grant permission on the client app logging through your admin account from azure portal 除了第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"
}
相关问题