【发布时间】:2020-06-29 08:31:51
【问题描述】:
我正在尝试使用 C# 中的 Graph API 将成员添加到 Azure Active Directory 中的组,但是当我运行代码时出现以下错误:
ServiceException:代码:BadRequest
消息:无效的 URL 格式 在@odata.bind 中为成员指定
下面是我的代码:
[AuthorizeForScopes(Scopes = new[] { Constants.GroupMemberReadWriteAll, Constants.DirectoryReadAsUser })]
public async Task<IActionResult> AddMembersToGroup()
{
MSGraphs.GraphServiceClient graphClient = GetGraphServiceClient(new[] { Constants.GroupMemberReadWriteAll, Constants.DirectoryReadAsUser });
var group = new MSGraphs.Group
{
AdditionalData = new Dictionary<string, object>()
{
{"members@odata.bind", "[\"https://graph.microsoft.com/v1.0/directoryObjects/c6e5c868-e2bd-46b0-b5f3-c39b5dfe42dc\",\"https://graph.microsoft.com/v1.0/directoryObjects/b2fc878b-a455-4315-b9e1-8594cbad3404\",\"https://graph.microsoft.com/v1.0/directoryObjects/79f06743-3bee-418e-8f4e-b381ebdfafc2\"]"}
}
};
await graphClient.Groups["{29f7e645-8de1-45fc-80a5-e76e0fa51340}"]
.Request()
.UpdateAsync(group);
return Ok();
}
如果我在这里遗漏了什么,请告诉我。
【问题讨论】:
标签: c# asp.net asp.net-core azure-active-directory azure-ad-graph-api