如何使用 powershell Az 模块授予 Azure AD 应用程序访问所需权限的权限

How to give Azure AD application access to required permissions using powershell Az module

我正在尝试重写创建 Azure AD 应用程序并为其分配权限的 powershell 脚本。该脚本正在使用 AzureAD 模块,我想使用新的 Az 模块,所以我可以 运行 它在 Linux/MacOS。

创建新应用程序很容易 (New-AzADApplication),但我遇到了权限问题。

旧脚本正在使用此代码分配权限:

#=============Graph Permissions========================
$req = New-Object -TypeName "Microsoft.Open.AzureAD.Model.RequiredResourceAccess"
$acc1 = New-Object -TypeName "Microsoft.Open.AzureAD.Model.ResourceAccess" -ArgumentList "df021288-bdef-4463-88db-98f22de89214","Role"

$req.ResourceAccess = $acc1
$req.ResourceAppId = "00000003-0000-0000-c000-000000000000" #Microsoft Graph   

Set-AzureADApplication -ObjectId $AppObjectId  -RequiredResourceAccess $req

但这不适用于 Linux/MacOS。有什么办法吗?如果不是来自 powershell 而不是使用其他方法?主要目标是 运行 从 Linux.

Azure CLI 易于上手,最适合用于管理 macOS 上的 Azure 资源的 Microsoft 跨平台命令行体验,Linux,或 Windows 和 运行 它来自命令行。

你的情况

在您的情况下,您可以尝试使用以下 CLI 命令获得应用程序权限:

az ad app permission add --api --api-permissions --id [--subscription]

例如

请参阅下面的“Sign in and read user profile”命令的添加图表 API 权限:

az ad app permission add --id eeba0b46-78e5-4a1a-a1aa-cafe6c123456 --api 00000002-0000-0000-c000-000000000000 --api-permissions 311a71cc-e848-46a1-bdf8-97ff7156d8e6=Scope

所需参数

permission

需要以下参数

--api

The target API to access.

--api-permissions

Space seperated list of =.

--id

Identifier uri, application id, or object id.

更多详细的CLI命令你也可以参考here

Note :

To executes above command you must need to install the CLI locally, run it in the browser with Azure Cloud Shell, or run in a Docker container. For installation reference you could see here

Powershell 命令

您可以找到详细信息 steps here

我希望这对您的预期有所帮助。让我们试试看。谢谢!