通过 CLI 将成员添加到 Azure Enterprise App

Add members to Azure Enterprise App through CLI

我们的 Azure AD 租户中有一个企业应用程序,用于将用户配置到另一个 SaaS 平台。目前它仅使用选项 "Sync only assigned users and groups" 进行设置,因为我们不希望整个目录都被带入。

我的问题很简单,有没有办法使用 az-cli(目前安装了 2.0.60 版)向该企业应用程序添加用户?

我查看了:

我希望 运行 有一个简单的角色分配命令,可以将 upn/objectId 的用户添加到企业应用程序。

我团队中的每个人都在使用 Mac,如果有更好的支持,我们可以使用 PowerShellCore。

谢谢!

您似乎无法通过 Azure CLI 执行此操作,我的解决方法是使用 powershell 来执行此操作。

Everyone in my team are using Mac's and we could use PowerShellCore if that has better support.

首先,您需要安装AzureAD.Standard.Preview powershell module which supports powershell core, you can understand the module is an equivalent of AzureAD module in powershell core, they have the same usage, it is a preview version, for more details see this link

然后尝试如下命令 New-AzureADUserAppRoleAssignment,此示例将用户分配给具有默认应用程序角色 ID 的应用程序。

New-AzureADUserAppRoleAssignment -ObjectId "<user objectid>" -PrincipalId "<user objectid>" -ResourceId "<service principal objectid(i.e. Enterprise Application objectid)>" -Id ([Guid]::Empty)

登录门户:

如果您想将用户分配给应用程序中的特定应用程序角色,请尝试以下命令。

$username = "<You user's UPN>"
$app_name = "<Your App's display name>"
$app_role_name = "<App role display name>"

# Get the user to assign, and the service principal for the app to assign to
$user = Get-AzureADUser -ObjectId "$username"
$sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'"
$appRole = $sp.AppRoles | Where-Object { $_.DisplayName -eq $app_role_name }

#Assign the user to the app role
New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId $user.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id

如果有帮助,我使用 'az rest' 完成了此操作。我们在这里都使用 Mac,powershell 核心似乎在几个地方坏了(不支持基于证书的登录,New-AzureADUserAppRoleAssignment cmdlet 对我们不起作用。我们使用的是预览版。Graph API 文档也很错误所以花了一些时间来获得正确的端点和有效负载。示例如下:

az rest --method post --uri https://graph.microsoft.com/beta/users/$user/appRoleAssignments --body "{\"appRoleId\": \"$appRoleId\",\"principalId\": \"$user\",\"resourceId\": \"$spObjectId\"}" --headers "Content-Type=application/json"

如果有人感兴趣,可以 post 上面的示例 bash 脚本来设置 vars 吗?