【发布时间】:2022-01-16 23:32:07
【问题描述】:
场景:应用程序中的管理员用户(在 AD 上的特定组中)将新记录添加到应用程序的数据库中,用于新的服务提供商。此过程向添加人员的电子邮件地址发送邀请,并且[应该] 将该新访客用户添加到 AD 上与其在应用程序上的功能及其地理位置相关的一组特定组中。
到目前为止,几乎所有事情都做得很好,但是在将新的来宾用户添加到组时,我收到以下错误:
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>'
在管理员同意的情况下,我获得了以下权限:
- AdministrativeUnit.ReadWrite.All(应用程序)
- Directory.AccessAsUser.All(委托)
- Directory.ReadWrite.All(应用程序)
- Group.ReadWrite.All(应用程序)
- GroupMember.Read.All(委托)
- GroupMember.ReadWrite.All(应用程序)
- PrivilegedAccess.ReadWrite.AzureADGroup(应用程序)
- User.Invite.All(应用程序)
- User.ManageIdentities.All(应用程序)
- User.Read(委托)
- User.Read.All(应用程序)
- User.ReadWrite.All(应用程序)
这是我的代码 - 我已删除敏感信息:
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);
}
}
按照下面的 MS Docs 页面所示,最初使用委派权限构建了这个,我更新了我的权限,使其更符合我们 Azure 上的另一个应用程序(由其他人开发),该应用程序有效,但既不是上面设置的权限,也不是指定的权限在下面的链接中工作 - 两种情况下都存在错误。
https://docs.microsoft.com/en-us/graph/api/group-post-members?view=graph-rest-1.0&tabs=http
那么我缺少什么权限?
【问题讨论】:
标签: c# azure microsoft-graph-api