繁体   English   中英

Microsoft Graph 更新 App Registration Approles API 补丁方法总是返回无法读取 JSON 请求负载

[英]Update App Registration Approles by Microsoft Graph API Patch method returns always Unable to read JSON request payload

在应用程序注册中,我想通过首先禁用活动角色然后删除它们来删除应用程序角色。 我通过开发人员工具检查了执行的命令,并提出以下请求:

$graphApiUrl = 'https://graph.microsoft.com/v1.0/applications'+'/'+$apiAppReg.appId
$body = '{"appRoles":[{"description":"Applications can read","displayName":"Reader","id":"xxxxxxx-xxxx-xxxx-xxxx-xxxxxx","isEnabled":false,"value":"Read","allowedMemberTypes":["Application"]}]}
'

az rest --method PATCH --url $graphApiUrl --headers 'Content-Type=application/json' --body '$body'

我在所有订单中都尝试过此操作,但这似乎导致了错误。

顺便提一句。 男孩是从 azure 网站的请求中复制的

从我这边复制后,我可以使用 PowerShell 满足您的要求。要禁用应用程序角色,我已经为我的应用程序中的每个应用程序角色设置IsEnabled=$false

下面是对我有用的脚本来禁用应用程序角色。

$App = Get-AzureADApplication -Filter "appId eq '$appId'"
$AppRoles = $app.AppRoles
for($I=0;$I -lt $AppRoles.Count;$I++)
{
    $app.AppRoles[$I].IsEnabled=$false
    Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $AppRoles
}

在此处输入图像描述

要从应用程序中删除应用程序角色,我使用$AppRoles.Remove($AppRoles[$I]) 下面是用于从我的应用程序中删除应用程序角色的完整代码。

for($I=0;$I -lt $AppRoles.Count;$I++)
{
    $AppRoles.Remove($AppRoles[$I])
    Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $AppRoles
}

下面是完整的工作代码

Connect-AzureAD

$AppId = "<APPLICATION_ID>"
$ObjectId = "<OBJECT_ID>"

$App = Get-AzureADApplication -Filter "appId eq '$appId'"
$AppRoles = $app.AppRoles
for($I=0;$I -lt $AppRoles.Count;$I++)
{
    $app.AppRoles[$I].IsEnabled=$false
    Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $AppRoles
}

for($I=0;$I -lt $AppRoles.Count;$I++)
{
    $AppRoles.Remove($AppRoles[$I])
    Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $AppRoles
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM