简体   繁体   English

我的应用需要哪些权限才能将用户添加到群组?

[英]What permissions does my app need before it can add users to groups?

Scenario: admin user in the app (is in a particular group on AD) adds a new record to the app's database for a new service provider.场景:应用程序中的管理员用户(在 AD 上的特定组中)将新记录添加到应用程序的数据库中以获取新的服务提供商。 This process sends an invitation to the email address of the person added and [should] adds that new guest user to a particular set of groups on the AD related to their function on the app and their geographic location.此过程向添加人员的 email 地址发送邀请,并且 [应该] 将该新访客用户添加到 AD 上与应用程序上的 function 及其地理位置相关的一组特定组中。

So far pretty much everything gets done just fine, but when it gets to adding the new guest user to the groups, I get the following error:到目前为止,几乎所有事情都做得很好,但是当将新的来宾用户添加到组时,我收到以下错误:

Microsoft.Graph.ServiceException: 'Code: Authorization_RequestDenied
    Message: Insufficient privileges to complete the operation.
    Inner error:
    AdditionalData:
        date: 2021-12-13T10:50:05
        request-id: <redacted>
        client-request-id: <redacted>
ClientRequestId: <redacted>'

I've got the following permissions granted with admin consent:在管理员同意的情况下,我获得了以下权限:

  • AdministrativeUnit.ReadWrite.All (Application) AdministrativeUnit.ReadWrite.All(应用程序)
  • Directory.AccessAsUser.All (Delegated) Directory.AccessAsUser.All(委托)
  • Directory.ReadWrite.All (Application) Directory.ReadWrite.All(应用程序)
  • Group.ReadWrite.All (Application) Group.ReadWrite.All(应用程序)
  • GroupMember.Read.All (Delegated) GroupMember.Read.All(委托)
  • GroupMember.ReadWrite.All (Application) GroupMember.ReadWrite.All(应用程序)
  • PrivilegedAccess.ReadWrite.AzureADGroup (Application) PrivilegedAccess.ReadWrite.AzureADGroup(应用程序)
  • User.Invite.All (Application) User.Invite.All(应用程序)
  • User.ManageIdentities.All (Application) User.ManageIdentities.All(应用程序)
  • User.Read (Delegated) User.Read(委托)
  • User.Read.All (Application) User.Read.All(应用程序)
  • User.ReadWrite.All (Application) User.ReadWrite.All(应用程序)

Here's my code - I've removed sensitive info:这是我的代码 - 我删除了敏感信息:

private async Task CreateUserInvitationAsync()
{
    // Send the invitation.
    var invitation = new Invitation
    {
        InvitedUserEmailAddress = Provider.Email,
        InviteRedirectUrl = $"{Request.Scheme}://{Request.Host}{this.Request.PathBase}/",
        SendInvitationMessage = true,
        InvitedUserType = "Guest"
    };
    var result = await graphClient.Invitations
        .Request()
        .AddAsync(invitation);

    // Update the provider to associate the Provider record with the new user id.
    var userId = result.InvitedUser.Id;
    var provider = await context.Providers.FindAsync(Provider.Id);
    provider.UserId = userId;

    // Add the user to groups so that role applications happen as necessary.
    var directoryObject = new DirectoryObject
    {
        Id = userId
    };

    string region = provider.Region switch
    {
        Region.Cpt => config["redacted"],
        Region.Dbn => config["redacted"],
        _ => config["redacted"]
    };

    var groups = new List<string>
    {
        region,
        config["redacted"]
    };

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

Having built this initially with delegated permissions as indicated on the MS Docs page below, I updated my permissions more in line with another app (developed by someone else) on our Azure which works but neither the permissions set above nor the one indicated in the link below work - the error persists in both cases.按照下面的 MS Docs 页面所示,最初使用委派权限构建了这个,我更新了我的权限,使其更符合 Azure 上的另一个应用程序(由其他人开发),该应用程序有效,但既不是上面设置的权限,也不是链接中指示的权限下面的工作 - 错误在两种情况下都存在。

https://docs.microsoft.com/en-us/graph/api/group-post-members?view=graph-rest-1.0&tabs=http https://docs.microsoft.com/en-us/graph/api/group-post-members?view=graph-rest-1.0&tabs=http

So what permissions am I missing?那么我缺少什么权限?

TL;DR set GroupMember.ReadWrite.All as an Application permission on your app and then add the app to the group where you're assigning members. TL;DRGroupMember.ReadWrite.All设置为您的应用程序的应用程序权限,然后将应用程序添加到您分配成员的组中。


It isn't a permissions issue.这不是权限问题。

By the time I found this solution, I'd added GroupMember.ReadWrite.All as an Application permission to the app and granted consent by an admin but the error persisted.当我找到此解决方案时,我已将GroupMember.ReadWrite.All作为Application权限添加到应用程序并获得管理员的同意,但错误仍然存在。

Note the permission description for GroupMember.ReadWrite.All :注意GroupMember.ReadWrite.All的权限描述:

Allows the app to list groups, read basic properties, read and update the membership of the groups this app has access to without a signed-in user.允许该应用列出组、读取基本属性、读取和更新此应用在没有登录用户的情况下有权访问的组的成员资格。 Group properties and owners cannot be updated and groups cannot be deleted.无法更新组属性和所有者,也无法删除组。

Of particular interest "of the groups this app has access to" .特别感兴趣的“这个应用程序可以访问的组”

My understanding of this turned out to be correct in that the app needed to be a member of the group in question so that it could add users to the group.我对此的理解被证明是正确的,因为应用程序需要成为相关组的成员才能将用户添加到组中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Asp.net Web API从Azure AD中读取用户组和组用户需要哪些应用程序注册预览权限/范围? - What app registration preview permissions/scopes required to read user groups and group users from azure AD using Asp.net web api? 邀请用户使用 Azure 应用需要哪些角色和权限? - What roles and permissions are needed to invite users to Azure app? 用户需要什么权限来验证Active Directory中的凭据? - What permissions does user need to validate credentials in Active Directory? 部署我的应用程序后,我的用户如何添加精灵和图像资源? - How can my users add sprite and image resources once my app is deployed? 有没有办法可以根据我的asp.net Web应用程序中的活动目录组提供权限? - Is there a way i can give permissions based on the groups of active directory in my asp.net web application? 逻辑删除工作正常,但是我的应用需要吗? - Tombstoning working, but does my app need it? 以编程方式使用C#为所有用户和组显示文件夹的权限 - Displaying permissions of a folder for all users and groups using C# Programatically RedirectToAction不能满足我的需求。 我有什么选择? - RedirectToAction does not do what I need. What are my options? 使用应用程序权限访问我的 OneDrive 时,“令牌中需要存在 scp 或角色声明” - "Either scp or roles claim need to be present in the token" when using app permissions to access my OneDrive .NET app.config 文件 — 这需要与我的应用程序一起分发吗? - .NET app.config file — does this need to be distributed with my app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM