如何使用 Azure PowerShell 或 Azure CLI 向应用程序注册添加 API 权限

问题描述 投票:0回答:1

尝试为应用程序注册分配角色,但难以在 AZ 模块中为 PowerShell 或 Azure CLI 识别合适的命令。

下面的 AzureAD Module 命令按预期运行:

New-AzureADServiceAppRoleAssignment -ObjectId $resourceObjectId -Id $roleId -PrincipalId $sourceServicePrincipalId -ResourceId $resourceObjectId

但是,我在将上述命令迁移到新模块时遇到了困难。我不确定为新命令指定哪个范围,从而导致迁移过程中出现问题。

请有人帮忙

我需要帮助将上述命令迁移到 Azure CLI/AZ 模块 powershell 脚本。

azure-powershell azure-cli azure-service-principal azure-app-registration microsoft-entra-id
1个回答
0
投票

我创建了一个名为 tasks.read

应用程序角色,具有以下属性:

enter image description here

现在,我运行下面的

Az
PowerShell 命令将此 App 角色 API 权限分配给应用程序注册:

Add-AzADAppPermission -ApplicationId $sourceAppId -ApiId $resourceappId -PermissionId $roleId -Type Role
Get-AzADAppPermission -ApplicationId $sourceAppId

回复:

enter image description here

当我在门户中检查相同内容时,API权限在应用程序注册下成功添加,如下所示:

enter image description here

要通过 Azure CLI 执行相同操作,您可以使用以下命令:

az ad app permission add --id <sourceAppObjId> --api <resourceAppId> --api-permissions <roleId>=Role --only-show-errors

回复:

enter image description here

如果您收到 “权限不足” 错误,请确保至少在目录下为您的用户分配 应用程序管理员 Entra 角色:

转到 Azure 门户 -> Microsoft Entra ID -> 角色和管理员 -> 所有角色 -> 选择角色 -> 添加分配

enter image description here

参考:

添加-AzADAppPermission(Az.Resources)|微软学习

© www.soinside.com 2019 - 2024. All rights reserved.