MS 图扩展然后过滤多个道具不应用过滤器
MS graph expanding and then filtering for multiple props does not apply filter
我正在尝试查询图表,以获取我租户中的所有用户,这些用户可以访问特定资源(即我的 Web 应用程序)并具有特定角色
这是我目前得到的:
https://graph.microsoft.com/v1.0/users?$select=id,givenName,surname,mail,preferredLanguage,externalUserState&$expand=appRoleAssignments($filter=resourceId eq ${resourceId} AND appRoleId eq ${appRole})
如您所见:
- 我得到了我所有的用户
- 我用
appRoleAssignments
扩展我的用户,这应该给我每个用户的应用程序分配,以及该分配的具体细节
- 我分别根据
resourceId
和 appRoleId
应用过滤器来过滤对象
调用有效,但我返回了我租户中的每个用户,这绝对不是我想要的 - 最好是,我只想返回有权访问我的 resourceId
的用户并分配了特定的 appRoleId
无法使用图表 API。
例如,如果我想根据许可证 SkuId 获取用户,您可以使用下面的 API :
https://graph.microsoft.com/v1.0/users?$count=true&$filter=assignedLicenses/any(s:s/skuId eq b05e124f-xxxx-xxxx-xxxx-8xxxxxxx)
它提供输出,因为分配的许可证是同一 Odata 查询的一部分。
但是如果您对 App Role Assignments 尝试同样的操作,则会出现以下错误:
由于User Context和AppRoleAssignments Context位于不同的Odata Context中。因此,当您调用查询时:
https://graph.microsoft.com/v1.0/users?$select=id,givenName,surname,mail,preferredLanguage,externalUserState&$expand=appRoleAssignments($filter=resourceId eq ${resourceId} AND appRoleId eq ${appRole})
第一部分 upto expand 成功并且 returns 值,但第二部分,即应用程序角色分配的过滤器不起作用,这就是您获取所有用户列表的原因。
作为解决方案,您可以通过使用条件参数来使用 PowerShell 脚本:
Connect-AzureAD
$users=Get-AzureADUser
$Name=@()
foreach ($user in $users) {
$approle=Get-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId
$resourceId= 'a19d7xx-xxxx-xxxx-xxx-c48c4d991411'
if ($approle.ResourceId -eq $resourceId){
$deviceprops = [ordered] @{
UserDisplayName = $approle.PrincipalDisplayName
}
$deviceobj = new-object -Type PSObject -Property $deviceprops
$Name += $deviceobj
}
}
$Name
输出:
参考:
Get-AzureADUser and Get-AzureADUserAppRoleAssignment and Install AzureAD Module
我正在尝试查询图表,以获取我租户中的所有用户,这些用户可以访问特定资源(即我的 Web 应用程序)并具有特定角色
这是我目前得到的:
https://graph.microsoft.com/v1.0/users?$select=id,givenName,surname,mail,preferredLanguage,externalUserState&$expand=appRoleAssignments($filter=resourceId eq ${resourceId} AND appRoleId eq ${appRole})
如您所见:
- 我得到了我所有的用户
- 我用
appRoleAssignments
扩展我的用户,这应该给我每个用户的应用程序分配,以及该分配的具体细节 - 我分别根据
resourceId
和appRoleId
应用过滤器来过滤对象
调用有效,但我返回了我租户中的每个用户,这绝对不是我想要的 - 最好是,我只想返回有权访问我的 resourceId
的用户并分配了特定的 appRoleId
无法使用图表 API。
例如,如果我想根据许可证 SkuId 获取用户,您可以使用下面的 API :
https://graph.microsoft.com/v1.0/users?$count=true&$filter=assignedLicenses/any(s:s/skuId eq b05e124f-xxxx-xxxx-xxxx-8xxxxxxx)
它提供输出,因为分配的许可证是同一 Odata 查询的一部分。
但是如果您对 App Role Assignments 尝试同样的操作,则会出现以下错误:
由于User Context和AppRoleAssignments Context位于不同的Odata Context中。因此,当您调用查询时:
https://graph.microsoft.com/v1.0/users?$select=id,givenName,surname,mail,preferredLanguage,externalUserState&$expand=appRoleAssignments($filter=resourceId eq ${resourceId} AND appRoleId eq ${appRole})
第一部分 upto expand 成功并且 returns 值,但第二部分,即应用程序角色分配的过滤器不起作用,这就是您获取所有用户列表的原因。
作为解决方案,您可以通过使用条件参数来使用 PowerShell 脚本:
Connect-AzureAD
$users=Get-AzureADUser
$Name=@()
foreach ($user in $users) {
$approle=Get-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId
$resourceId= 'a19d7xx-xxxx-xxxx-xxx-c48c4d991411'
if ($approle.ResourceId -eq $resourceId){
$deviceprops = [ordered] @{
UserDisplayName = $approle.PrincipalDisplayName
}
$deviceobj = new-object -Type PSObject -Property $deviceprops
$Name += $deviceobj
}
}
$Name
输出:
参考:
Get-AzureADUser and Get-AzureADUserAppRoleAssignment and Install AzureAD Module