通过PowerShell检索Azure AD应用程序的“ API权限”

时间:2020-03-20 06:06:51

标签: azure powershell azure-active-directory

出于报告和监视的目的,我想检索Azure门户中针对应用程序(“应用程序注册”)显示的“ API权限”信息。

我尝试了以下代码

$app = Get-AzureADApplication -ObjectId 'aa7e174d-2639-4ac7-9b11-6799466c3c9b'
$app.Oauth2Permissions

但这只会产生以下信息:

AdminConsentDescription : Allow the application to access foobar_HVV on behalf of the signed-in user.
AdminConsentDisplayName : Access foobar_HVV
Id                      : h1285f9d5-b00d-4bdb-979d-c4d6487fa000
IsEnabled               : True
Type                    : User
UserConsentDescription  : Allow the application to access foobar_HVV on your behalf.
UserConsentDisplayName  : Access foobar_HVV
Value                   : user_impersonation

但是应用程序“ foobar_HVV”的“ API权限”显示了完全不同的权限。对于我的报告,尤其需要每个权限的“ Typ”(委托,应用程序)和“ Status”。

1 个答案:

答案 0 :(得分:4)

如果要获取API permissions,则需要使用以下命令。

$app = Get-AzureADApplication -ObjectId '<object-id of the App Registration>'
$app.requiredResourceAccess | ConvertTo-Json -Depth 3

enter image description here

ResourceAppId是API服务主体的Application ID,例如Microsoft GraphResourceAccess包括您添加到应用程序的权限,Scope代表Delegated permissionRole代表Application permission

我的API权限:

enter image description here

要检查API权限的详细信息,您需要使用以下命令。例如,我们想知道屏幕快照中Id5b567255-7703-4780-807c-7be8301ae99b的权限的细节,其TypeRole的权限,因此我们需要使用{{1} }。

$sp.AppRoles

enter image description here

如果您想获取$sp = Get-AzureADServicePrincipal -All $true | Where-Object {$_.AppId -eq '00000003-0000-0000-c000-000000000000'} $sp.AppRoles | Where-Object {$_.Id -eq '5b567255-7703-4780-807c-7be8301ae99b'} Delegated permissionType),则需要使用:

Scope

enter image description here

要检查$sp = Get-AzureADServicePrincipal -All $true | Where-Object {$_.AppId -eq '00000003-0000-0000-c000-000000000000'} $sp.Oauth2Permissions | Where-Object {$_.Id -eq 'e1fe6dd8-ba31-4d61-89e7-88639da4683d'} ,没有直接方法,您需要检查与AAD租户中的AD App对应的服务主体的管理员授予的权限。

首先,获取服务主体Status

$appsp

获取已被授予的$app = Get-AzureADApplication -ObjectId '<object-id of the App Registration>' $appsp = Get-AzureADServicePrincipal -All $true | Where-Object {$_.AppId -eq $app.AppId} Delegated permissionsStatus):

Granted

enter image description here

Get-AzureADServicePrincipalOAuth2PermissionGrant -ObjectId $appsp.ObjectId -All $true | ConvertTo-Json 是API的服务主体的ResourceId

enter image description here

获取已被授予的Object IdApplication permissionsStatus):

Granted

Get-AzureADServiceAppRoleAssignedTo -ObjectId $appsp.ObjectId | ConvertTo-Json 是第一个屏幕快照中Id中的Id

enter image description here

如果未授予许可(ResourceAccessStatus),则上述命令将不会获得许可。

例如,我在门户中添加了一个新的Not Granted,然后再次运行该命令,我们仍然可以获得已授予的权限。

enter image description here

enter image description here