azure - 如何使用 powershell Az 模块为 Azure AD 应用程序提供所需权限的访问权限

标签 azure powershell azure-active-directory az

我正在尝试重写 powershell 脚本来创建 Azure AD 应用程序并为其分配权限。该脚本使用 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 易于上手,最适合用于 Microsoft 的跨平台命令行体验,用于管理 macOS、Linux 或 Windows 上的 Azure 资源并从命令行运行它。

您的案例

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

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

例如

请参阅下面添加“Sign in and read user profile ”命令的 Graph 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

我希望这对您的期望有所帮助。让我们尝试一下。谢谢!

关于azure - 如何使用 powershell Az 模块为 Azure AD 应用程序提供所需权限的访问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55385802/

相关文章:

azure - "Cloud endpoint creation failed"的一些问题

powershell - 自动执行需要用户输入的.cmd文件

json - 如何防止PowerShell将\添加到字符串

powershell - 缺少 Microsoft Graph ServicePrincipal

自定义容器中的 Azure Web App,环境变量未从应用服务传播到容器

azure - 通过 azure 管道克隆 Gitlab 存储库,显示 SSL 错误

logging - Powershell 计划任务冲突?

azure - Asp 核心 2.2 Azure 事件目录 : Authorization failed

powershell - 从 powershell 获取当前用户的 Azure Active Directory 资源访问 token ?

azure - 升级到 asp.net core rc2 后发布到 Azure 应用服务崩溃