我正在尝试使用Graph API将用户添加到Azure AD组。
我可以创建和更新用户,但是当我尝试将用户添加到一个"已启用邮件的安全组"我收到这个错误:
System.Data.Services.Client.DataServiceClientException:
无法更新源自外部服务的对象的指定属性
{
"odata.error": {
"code": "Request_BadRequest",
"message": {
"lang": "en",
"value": "Unable to update the specified properties for objects that have originated within an external service."
},
"date": "2018-01-04T14:21:20",
"requestId": "d6c76938-03d3-4668-8f69-2ed227f15063",
"values": null
}
}
我可以将用户添加到" security"或" Office"成员组,但无法将成员(用户)添加到"已启用邮件的安全组"。
我该如何解决这个问题?
这是我的代码:
public async Task AddGroupMember(IUser newUser)
{
try
{
var grpAlleBrukere = GetAlleBrukere();
var upn = newUser.UserPrincipalName;
var grpAlleBrukereId = GetAlleBrukere();
IGroupFetcher groupFetcher = adClient.Groups.GetByObjectId(grpAlleBrukereId);
Group group = (Group)groupFetcher.ExecuteAsync().Result;
if (group.ObjectId != null)
{
IUser user = adClient.Users.Where(u => u.UserPrincipalName.Equals(upn, StringComparison.CurrentCultureIgnoreCase)).ExecuteAsync().Result.CurrentPage.ToArray().First();
if (user != null)
{
//check wather user aleady present into group or not
IDirectoryObject userExists = group.Members.Where(u => u.ObjectId == user.ObjectId).FirstOrDefault();
if (userExists == null)
{
group.Members.Add(user as DirectoryObject);
group.UpdateAsync().Wait();
}
}
else
throw new Exception("User is null.");
}
}
catch(Exception ex)
{
Console.WriteLine("ERROR: " + ex.Message);
Console.WriteLine("ERROR: " + ex.Source);
Console.WriteLine("ERROR: " + ex.StackTrace);
Console.WriteLine("ERROR: " + ex.InnerException);
}
}