【发布时间】:2019-06-13 23:32:21
【问题描述】:
我正在使用图形 API 来检索用户图像和 SharePoint 列表项,并使用托管服务身份进行身份验证。 我成功地使用 powershell 为我的服务身份添加了所需的权限。
<#
ERRORS OUT BUT WORKS. YOU CAN VALIDATE BY USING THE GRAPH EXPLORER TO CALL:
https://graph.microsoft.com/beta/servicePrincipals/{msiObjectId}/appRoleAssignedTo
NOTE: Get-AzureADServiceAppRoleAssignedTo DOES NOT WORK, MUST USE GRAPH EXPLORER FOR VALIDATION
#>
Connect-AzureAD
$msiObjectId = "12345678-1234-1234-1234-123456789101"
$app_name = "Microsoft Graph"
$role_names = @("Sites.Read.All", "User.Read.All", "Directory.Read.All")
$sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'"
$role_names | foreach {
$role_name = $_
$appRole = $sp.AppRoles | Where-Object { ($_.DisplayName -eq $role_name) -or ($_.Value -eq $role_name) }
New-AzureADServiceAppRoleAssignment -ObjectId $msiObjectId -PrincipalId $msiObjectId -ResourceId $sp.ObjectId -Id $appRole.Id
}
Disconnect-AzureAD
当我将应用程序发布到分配给服务标识的天蓝色服务时,此错误但添加了权限并且工作正常。
我正在使用 Microsoft.Azure.Services.AppAuthentication 来检索令牌并进行调用。
using Microsoft.Azure.Services.AppAuthentication;
...
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", await new AzureServiceTokenProvider().GetAccessTokenAsync("00000003-0000-0000-c000-000000000000"));
...
问题出在本地开发中,这取决于我的凭据。这成功地获得了一个具有一些基本图形访问权限的令牌,例如 /me 和 /user basic,但是当我尝试检索列表或用户图像时,我收到以下错误:
{
"error": {
"code": "accessDenied",
"message": "The caller does not have permission to perform the action.",
"innerError": {
"request-id": "55555555-1234-1234-1234-123456789101",
"date": "2019-06-12T17:05:31"
}
}
}
我已经尝试在 powershell 代码中使用我自己的对象 ID 代替 $msiObjectId,并且还尝试将 New-AzureADServiceAppRoleAssignment 更改为 New-AzureADUserAppRoleAssignment,但都没有成功。我还在 UI 中尝试了所有可能的方法,但找不到添加权限的方法,并尝试了 https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize?client_id=00000003-0000-0000-c000-000000000000&scope=offline_access%20User.Read.All%20Sites.Read.All,这给了我一个关于没有回复 url 的错误,也不起作用。
我想我可能需要为我的帐户添加一些委托权限来代替应用程序角色分配,但无论如何我都找不到这样做。我可以使用$sp.Oauth2Permissions 查看权限,但无法找到授予自己这些权限的方法。
这可能吗?如果可以,怎么做?
基本上,我需要我的凭据(没有应用程序)在使用 new AzureServiceTokenProvider().GetAccessTokenAsync()) 时至少具有对 Microsoft Graph (GraphAggregatorService) 的“Sites.Read.All”和“User.Read.All”访问权限
【问题讨论】:
标签: azure powershell permissions microsoft-graph-api acs-serviceidentity