无法在 Microsoft Graph 中获得权限的 guids api

Can't get permission's guids in microsoft graph api

我想创建一个具有特定 GraphAPI 权限的应用程序。我想自动完成,所以 powershell 是我的选择。唯一缺少的是 GraphAPI 权限的 GUID,在超级棒的 Microsoft 文档中找不到。

我从其他几个已经问过的问题(并标记为已回答哈哈)中收集到的是:

    Connect-AzAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal 
    $graph = Get-AzADServicePrincipal -ApplicationId "00000003-0000-0000-c000-000000000000"
    $graph.AppRoles

这应该为我提供 GraphAPI 必须提供的所有应用程序权限的列表。 不幸的是,我收到的对象中不存在 $graph.AppRoles($graph.Oauth2Permissions)。 (我知道委派权限和应用程序权限之间的区别,并且可以在 Oauth2Permissions/AppRoles 属性 中找到它们。)

有什么建议吗?

Oauth2Permissions 和 AppRoles 属性存在于 Azure AD Powershell 中。

Connect-AzureAD -TenantId $tenantId -Credential $psCred
$graphsp1 = Get-AzureADServicePrincipal -Filter "AppId eq '00000003-0000-0000-c000-000000000000'"
$graphsp.AppRoles
$graphsp.Oauth2Permissions

您还可以使用 Microsoft Graph API 获取 Application/Delegated 权限。

GET https://graph.microsoft.com/v1.0/servicePrincipals?$filter=appId eq '00000003-0000-0000-c000-000000000000'

只需使用 Invoke-RestMethod 在 Powershell 中调用 Microsoft Graph。

感谢 Allen Wu 的回答,我能够提取权限 GUID。

虽然,不是

GET https://graph.microsoft.com/v1.0/servicePrincipals?$filter=appId eq '00000003-0000-0000-c000-000000000000'

保存信息的这个调用是

GET https://graph.microsoft.com/v1.0/applications/"

这是一个。 然后通过一些基本的过滤,我得到了我需要的东西

$headers = getToken
$uri = "https://graph.microsoft.com/v1.0/applications/"
$result = Invoke-RestMethod -Uri $uri -Headers $headers -Method 'Get'
do {
    $result.value | ForEach-Object {
        if( $_.displayName -eq "YOUR_APPLICATION_DISPLAYNAME") {
            $result = $_.requiredResourceAccess | Where-Object resourceAppId -eq "00000003-0000-0000-c000-000000000000"
            break
        }
    }
    $result = Invoke-RestMethod -Uri $result.'@odata.nextLink' -Headers $headers -Method 'Get'
    $result = $result
}
while($result.'@odata.nextLink')

在 $result 中我们有这个

resourceAppId:"00000003-0000-0000-c000-000000000000"
resourceAccess:[Object[14]]
[0]:@{id=e1fe6dd8-ba31-4d61-89e7-88639da4683d; type=Scope}
[1]:@{id=660b7406-55f1-41ca-a0ed-0b035e182f3e; type=Role}
[2]:@{id=242607bd-1d2c-432c-82eb-bdb27baa23ab; type=Role}
[3]:@{id=2280dda6-0bfd-44ee-a2f4-cb867cfc4c1e; type=Role}
[4]:@{id=46890524-499a-4bb2-ad64-1476b4f3e1cf; type=Role}
[5]:@{id=98830695-27a2-44f7-8c18-0c3ebc9698f6; type=Role}
[6]:@{id=9a5d68dd-52b0-4cc2-bd40-abcf44ac3a30; type=Role}
[7]:@{id=afdb422a-4b2a-4e07-a708-8ceed48196bf; type=Role}
[8]:@{id=70dec828-f620-4914-aa83-a29117306807; type=Role}
[9]:@{id=7ab1d382-f21e-4acd-a863-ba3e13f7da61; type=Role}
[10]:@{id=5b567255-7703-4780-807c-7be8301ae99b; type=Role}
[11]:@{id=230c1aed-a721-4c5d-9cb4-a90514e508ef; type=Role}
[12]:@{id=18a4783c-866b-4cc7-a460-3d5e5662c884; type=Role}
[13]:@{id=df021288-bdef-4463-88db-98f22de89214; type=Role}

您可以看到,根据resourceAppId,我们正在谈论Microsoft GraphAPI 权限。类型 属性 表示它是委托权限还是申请权限。范围=委托 角色=应用程序