如何将用户分配给 Azure 资源组

How to assign a user to an Azure Resource Group

我正在尝试创建一个新的资源组,一个新的 Active Directory 用户,然后将该用户作为参与者分配给资源组。

到目前为止,我已经使用 Microsoft.Azure.Management.ResourceManager 成功创建了资源组,并使用 Microsoft.Graph 创建了 AD 用户。我可以在 Azure 中看到并且可以访问它们。

但是,我无法在 Resource Manager 或 Graph 中清楚地找到如何使用 C# 将用户分配到资源组 API。

我可以在这里看到如何在其他所有地方做到这一点 > https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal

我将其视为图表 API 调用 graphClient.DeviceManagement.RoleAssignments 但是,从属性中我无法清楚地看到我将资源组详细信息放在哪里。

下面是我的尝试,但出现错误: 请求不适用于目标租户

var roleAssignment = await graphClient.DeviceManagement.RoleAssignments.Request().AddAsync(new DeviceAndAppManagementRoleAssignment
                {
                    DisplayName = "Test Role",
                    Members = new List<string>
                    {
                        createdUser.Id // GUID of new User
                    },
                    ResourceScopes = new List<string>
                    {
                        "/subscriptions/04cbb440-e619-4c8f-869f-8dc4d7dd6e42/resourceGroups/NewResourceGroup" // ID of Resource Group
                    },
                    RoleDefinition = new RoleDefinition
                    {
                        RolePermissions = new List<RolePermission> {

                            new RolePermission {
                                ResourceActions = new List<ResourceAction>
                                {
                                    new ResourceAction {
                                        AllowedResourceActions = new List<string> {"*"},
                                        NotAllowedResourceActions = new List<string>
                                        {
                                            "Microsoft.Authorization/*/Delete",
                                            "Microsoft.Authorization/*/Write",
                                            "Microsoft.Authorization/elevateAccess/Action"
                                        }
                                      }
                                }
                            }
                        }
                    }
                }).ConfigureAwait(false);

有人可以告诉我如何轻松地做到这一点或在哪里寻找吗?

据我所知,我们应该使用 Azure management REST API 来管理对 A​​zure 资源 的访问。

RBAC Graph API 适用于 Intune 租户需要 有效的 Intune 许可证。它管理 Intune 中基于角色的访问。