为了进行报告和监视,我想检索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”。
如果要获取API permissions
,则需要使用以下命令。
$app = Get-AzureADApplication -ObjectId '<object-id of the App Registration>'
$app.requiredResourceAccess | ConvertTo-Json -Depth 3
的ResourceAppId
是Application ID
该API例如服务主体的Microsoft Graph
,在ResourceAccess
包括已添加到应用程序的权限,该Scope
装置Delegated permission
,Role
装置的Application permission
。
我的API权限:
要检查API权限的详细信息,您需要使用以下命令。例如,我们想知道其权限的细节Id
是5b567255-7703-4780-807c-7be8301ae99b
在截图,它Type
就是Role
,所以我们需要使用$sp.AppRoles
。
$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 permission
(Type
is Scope
),则需要使用:
$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'}
要检查Status
,没有直接方法,您需要检查与AAD租户中的AD App对应的服务主体的管理员授予的权限。
首先,获取服务主体$appsp
:
$app = Get-AzureADApplication -ObjectId '<object-id of the App Registration>'
$appsp = Get-AzureADServicePrincipal -All $true | Where-Object {$_.AppId -eq $app.AppId}
获取Delegated permissions
其已被授予(Status
是Granted
):
Get-AzureADServicePrincipalOAuth2PermissionGrant -ObjectId $appsp.ObjectId -All $true | ConvertTo-Json
该ResourceId
是Object Id
API的服务主体的:
获取Application permissions
其已被授予(Status
是Granted
):
Get-AzureADServiceAppRoleAssignedTo -ObjectId $appsp.ObjectId | ConvertTo-Json
该Id
是Id
在ResourceAccess
第一截图。
如果尚未授予该权限(Status
is Not Granted
),则不会通过上述命令获得该权限。
例如,我Application permission
在门户中添加一个新的,然后再次运行命令,我们仍然可以获得已授予的权限。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句