用户 appRoleAssignments 使用过滤器 resourceid eq 抛出错误

users appRoleAssignments throwing error with filter resourceid eq

我需要实施删除用户 appRoleAssignments 的逻辑,但我只有用户 ID 和 resourceId,我尝试使用用户 appRoleAssignments 图 API,但它需要 .是否有任何选项可以使用 userId 和 resourceId

过滤 appRoleAssignments

尝试了 Get 和 Delete 操作的 resourceId 过滤器选项,但都抛出了以下错误。 注册:https://graph.microsoft.com/beta/users//appRoleAssignments?$filter=resourceId eq ''

{ "error":{ "code": "BadRequest", "message": "Invalid filter clause", "innerError":{ "date": "2020-06-14T17:30:11", "request-id": "someid" } } }

我不想使用userId获取一个用户的所有appRoleAssignments并用id执行删除操作。

我也可以在我这边重现您的问题,要成功获取带有 resourceId 的 appRoleAssignment,请不要传递 ''"",只需使用下面的示例即可。

GET https://graph.microsoft.com/beta/users/<object-id>/appRoleAssignments?$filter=resourceId eq 90bf87ee-5d26-49bd-aeee-7532a8f32cc0

然后在响应中复制 id,删除下面的 appRoleAssignment,效果很好。

DELETE https://graph.microsoft.com/beta/users/<object-id>/appRoleAssignments/<id>

更新:

如果你也可以接受使用 powershell,你可以使用下面的脚本,确保你已经安装了 AzureAD 模块。

Connect-AzureAD
$userid = "<user object id>"
$resourceid = "<resource id>"

$id = (Get-AzureADUserAppRoleAssignment -ObjectId $userid -All $true | Where-Object {$_.ResourceId -eq $resourceid}).ObjectId
Remove-AzureADUserAppRoleAssignment -ObjectId $userid -AppRoleAssignmentId $id