azure - 如何从外部应用程序管理Azure应用程序角色

标签 azure azure-active-directory azure-app-registration

我正在构建一个应用程序,该应用程序使用基于角色的访问,并在 Azure 应用程序注册中创建了自定义应用程序角色,并且还为一些用户分配了企业应用程序中的角色。我的问题是,我们可以通过应用程序而不是使用 Azure 将这些自定义应用程序角色删除并分配给用户吗?

我尝试使用 Microsoft Graph API 来解决这个问题。在前端(React)中,我通过图形 API 调用来实现此目的并且工作正常。但它需要启用“AppRoleAssignment.ReadWrite.All”权限,这对于我正在执行的任务来说似乎非常高级,因为它可以将任何角色(自定义或 AAD 角色)分配给任何用户、应用程序,并且感觉不安全将此范围提供给我的最终用户,即使只有管理员角色将执行此任务。有没有更好的方法来实现这一点。还有一种方法可以将其中一个自定义角色默认分配给新用户吗?感谢您的帮助!

最佳答案

我尝试在我的环境中重现相同的内容,以使用 Powershell 将应用程序角色分配给用户

您可以按照以下步骤获取用户对象 ID 和应用程序对象 ID

用户对象 ID:

转到 Azure 门户 > Azure Active Directory > 用户 > 选择用户

enter image description here

应用程序对象 ID:

转到 Azure 门户 > Azure Active Directory > 企业应用程序 > 选择您的应用

enter image description here

Powershell 脚本:

Connect-AzureAD
$user = Get-AzureADUser -ObjectId "userobjectID"
$servicePrincipal = Get-AzureADServicePrincipal -ObjectId "AppobjectID"
$role = $app.AppRoles | Where-Object {$_.DisplayName -eq "Reader"}
#Check Approle ID
$role.Id
New-AzureADUserAppRoleAssignment -ObjectId "userobjectID" -PrincipalId $user.ObjectId -ResourceId $servicePrincipal.ObjectId -Id "ApproleID"
 Remove-AzureADUserAppRoleAssignment -ObjectId "userobjectId" -AppRoleAssignmentId "ApprolID"

回应:

enter image description here

运行上述代码后,应用程序角色将添加到应用程序中,如下所示。

enter image description here

Also is there a way to assign one of the custom roles as default to new users?

创建了动态组,以便在新用户加入时向用户分配应用角色。

转到 Azure 门户 > Azure Active Directory > 组 > 新建组。

enter image description here

创建群组后,将应用角色分配给用户,如下所示。

转到 Azure 门户 > Azure Active Directory > 企业应用程序 > 所有应用程序 > 选择您的应用程序

enter image description here

引用:New-AzureADUserAppRoleAssignment & Remove-AzureADUserAppRoleAssignment

关于azure - 如何从外部应用程序管理Azure应用程序角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75572720/

相关文章:

azure - Get-AzADAppPermission Id 转换器

Azure AD 管理员同意吗? Multi-Tenancy 应用程序管理

azure - 使用 VM 名称 Ping 同一子网中的 Azure VM

azure - 获得未经授权的访问以将数据从 blob 移动到共享点

c# - 如何使用 Azure Active Directory .NET SDK 删除 AppRoleAssignment?

authentication - 连接到 Azure SQL 数据库时的 Active Directory 身份验证

azure-active-directory - 无需客户端密码即可使用应用程序注册

azure - 从 octopus 部署到 azure 出现连接错误

java - 钻到 Hive 连接错误(org.apache.thrift.transport.TTransportException java.net.SocketException : Broken pipe (Write failed))

azure - Azure ACS 和 Azure AD B2C 之间有什么区别?