gpt4 book ai didi

c# - 将 guest 用户添加到 Azure AD 组失败且权限设置正确

转载 作者:行者123 更新时间:2023-12-03 07:04:07 24 4
gpt4 key购买 nike

我通过我的网络应用程序邀请用户加入我的组织,并将他们添加到组中,这些组将用于确定他们可以使用网络应用程序的哪些部分,因为我已经将这些组与我的不同角色相关联。

对组织的邀请正常进行,但当我尝试将用户添加到组时,我收到 Microsoft.Graph.ServiceException ,如下所示:

'Code: Authorization_RequestDeniedMessage: Insufficient privileges to complete the operation.

权限不足似乎与我在应用程序注册时获得管理员同意后获得的应用程序权限不同:

  • Directory.ReadWrite.All,以及
  • GroupMember.ReadWrite.All

在我的一生中,我在 azure 门户中找不到与“权限”相关的任何内容,因为它涉及组管理,所以我必须假设权限就是它所指的;只是,我不知道除了这两个之外它还在寻找什么权限。

根据 MS Docs article on adding members to groups 上指示的权限,我正在使用以下权限初始化 MS Graph:

var initialScopes = new string[]
{
// Directory.ReadWrite.All
Constants.Graph.DirectoryReadWrite,
// GroupMember.ReadWrite.All
Constants.Graph.GroupMemberReadWrite,
// Group.ReadWrite.All
Constants.Graph.GroupReadWrite,
// RoleManagement.ReadWrite.Directory
Constants.Graph.RoleManagementReadWriteDirectory
};
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(options =>
{
// Redacted for brevity
})
.EnableTokenAcquisitionToCallDownstreamApi(options =>
configuration.Bind("AzureAd", options), initialScopes)
.AddMicrosoftGraph(configuration.GetSection("GraphAPI"))

我的配置的 GraphAPI 部分如下所示:

"GraphAPI": {
"BaseUrl": "https://graph.microsoft.com/v1.0",
"Scopes": "GroupMember.ReadWrite.All Group.ReadWrite.All Directory.ReadWrite.All RoleManagement.ReadWrite.Directory"
},

我不可能缺少任何必需的权限(根据文档指示)。我已经注销并重新登录了几次(并且还完全清除了该网站的所有浏览数据)以刷新 token 身份验证 token ,但仍然没有运气。

我将受邀用户添加到组的代码:

// Determine the ID of the regional group to which the user should be added.
string region = this.Provider.Region switch
{
Region.Redacted => config["Groups:redacted"],
Region.Redacted => config["Groups:redacted"],
_ => config["Groups:redacted"]
};

// Add the user to the regional group and to the group for the user's intended role.
var groups = new List<string>
{
region,
config["Groups:redacted"]
};

foreach (var group in groups)
{
await graphClient.Groups[group].Members.References
.Request()
.AddAsync(directoryObject);
}

这里我需要任何额外的权限吗?如果不是,错误实际表明问题是什么以及如何纠正它?

最佳答案

鉴于您请求的委派权限(应涵盖所有场景,包括可分配角色的组),最可能的原因是登录用户无权管理相关组的成员资格.

一般来说,是否允许用户管理群组的成员资格取决于群组的类型以及用户是否是群组的所有者:

  • 所属群组:
    • 所有成员(member)用户
  • 安全组,而非可分配角色的组:
    • Intune 管理员
    • 知识管理员
    • 知识经理
    • Windows 365 管理员
  • Microsoft 365 组,而非可分配角色的组:
    • Exchange 管理员
    • SharePoint 管理员
    • 团队管理员
  • 安全组和 Microsoft 365 组,而不是可分配角色的组:
    • 用户管理员
    • 群组管理员
    • Identity Governance 管理员可以管理
  • 可分配角色的组,而不是安全组或 Microsoft 365 组:
    • 特权角色管理员
  • 所有组,包括可分配角色的组
    • 全局管理员

(此信息本质上是此处列出的内容的基础: https://learn.microsoft.com/en-us/azure/active-directory/roles/permissions-reference ,也可以通过查询 GET .../roleManagement/directory/roleDefinitions 从 Microsoft Graph 检索。)

关于c# - 将 guest 用户添加到 Azure AD 组失败且权限设置正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71739195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com