我使用 Microsoft Graph API 以编程方式注册客户端应用程序、资源服务器,并将角色从资源服务器分配给客户端应用程序。以下是遵循的步骤:
-
获取访问令牌 -->https://login.windows.net/ https://login.windows.net//oauth2/token/?api-version=1.6
-
客户端应用程序注册 -->https://graph.windows.net/ https://graph.windows.net//applications/?api-version=1.6
-
客户服务负责人
-
在清单中使用以下应用程序角色注册资源服务器:
"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"
}
],
-
资源服务器服务主体创建
-
将角色分配给客户端应用程序。
当我尝试使用客户端应用程序的凭据获取访问令牌时,我没有获得 JWT 中的任何角色,也没有获得资源服务器的任何信息。
我什至从客户端应用程序中的门户授予资源服务器角色的权限。但仍然没有运气。
任何帮助将不胜感激。如果您需要更多详细信息,请告诉我。
Thanks.
@2017年11月14日更新:
请找到 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 中的角色。
权限是通过 Portal 从 Resource_API_11092017 授予的。