C# 如何将用户分配到Azure资源组
我正在尝试创建一个新的资源组,一个新的Active Directory用户,然后将该用户作为参与者分配给资源组 到目前为止,我已经使用C# 如何将用户分配到Azure资源组,c#,azure,azure-active-directory,azure-resource-manager,azure-ad-graph-api,C#,Azure,Azure Active Directory,Azure Resource Manager,Azure Ad Graph Api,我正在尝试创建一个新的资源组,一个新的Active Directory用户,然后将该用户作为参与者分配给资源组 到目前为止,我已经使用Microsoft.Azure.Management.ResourceManager成功创建了资源组,并使用Microsoft.Graph创建了广告用户。我可以在Azure中看到这两个,也可以访问它们 但是,无论是在资源管理器还是图形API中,我都无法清楚地找到如何使用C#将用户分配到资源组 我可以在这里的其他地方看到如何做到这一点> 我将其视为Graph API
Microsoft.Azure.Management.ResourceManager
成功创建了资源组,并使用Microsoft.Graph
创建了广告用户。我可以在Azure中看到这两个,也可以访问它们
但是,无论是在资源管理器还是图形API中,我都无法清楚地找到如何使用C#将用户分配到资源组
我可以在这里的其他地方看到如何做到这一点>
我将其视为Graph API调用graphClient.DeviceManagement.RoleAssignments
但是,从属性中,我无法清楚地看到我将资源组详细信息放在了哪里
下面是我的尝试,但我得到一个错误:
请求不适用于目标租户
var roleasignment=wait graphClient.DeviceManagement.roleasignments.Request().AddAsync(新设备和应用管理roleasignment
{
DisplayName=“测试角色”,
成员=新列表
{
createdUser.Id//GUID新用户
},
ResourceScopes=新列表
{
“/subscriptions/04cbb440-e619-4c8f-869f-8dc4d7dd6e42/resourceGroups/NewResourceGroup”//ResourceGroup的ID
},
角色定义=新角色定义
{
角色权限=新列表{
新角色许可{
ResourceActions=新列表
{
新资源行动{
AllowedResourceActions=新列表{“*”},
NotAllowedResourceActions=新列表
{
“Microsoft.Authorization/*/Delete”,
“Microsoft.Authorization/*/Write”,
“Microsoft.Authorization/elevateAccess/Action”
}
}
}
}
}
}
}).配置等待(错误);
有人能告诉我如何轻松地做到这一点,或者在哪里查找吗?据我所知,我们应该使用来管理对Azure资源的访问
is forIntune需要租户的活动Intune许可证。它管理Intune中基于角色的访问。您应该使用Azure管理REST API而不是Microsoft Graph API@TonyJu我知道这可能是一个选项,但为什么我不能使用Graph SDK?RBAC Graph API是用于Intune的,租户需要活动Intune许可证@好的,谢谢你。我将把它作为一个解决方案,但我会留下问题,因为我仍然想知道你将如何使用Graph API来实现这一点。我正在寻找的是一种通过SDK而不是API来实现这一点的方法。
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);