azure - 通过 PowerShell 检索 Azure AD 应用程序的“API 权限”
问题描述
出于报告和监视目的,我是否喜欢检索 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”(代表,应用程序)和“状态”。
解决方案
如果你想得到API permissions
,你需要使用下面的命令。
$app = Get-AzureADApplication -ObjectId '<object-id of the App Registration>'
$app.requiredResourceAccess | ConvertTo-Json -Depth 3
ResourceAppId
是API的Application ID
服务主体的,例如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
在portal中添加了一个新的,然后再次运行命令,我们仍然可以得到已经授予的权限。
推荐阅读
- python - Logistic回归的多个问题(1.所有CV值具有相同的分数,2.分类报告和准确性不匹配)
- flutter - Flutter:创建一个没有默认构造函数的类的新实例并更改一些属性
- amazon-web-services - EMR Presto 6.3.0 未正确利用内存,因此“不同”查询速度较慢
- python - sqlalchemy 过滤少数具有不同数据类型的列
- c# - Selenium:从电子邮件文本字段/文本框中获取字符串
- java - 如何修改现有的jar文件?
- c++ - 如何动态优化多字段比较中的字段顺序
- cron - crontab 没有删除文件夹中的文件
- sql - 在 SQL Server 2012 中使用 SP_AddRole 添加角色时,数据库中已有一个名为“Test”的对象
- powershell - 使用 powershell 更新重复数组的字段值