Azure GraphClient library removes user from group

The azure laser graphic library was updated on December 22nd and the method of adding a user to the group was fixed.

Azure Active Directory Graph Client 2.0 - Context does not currently track an object

But is it possible to remove a user from a group?

I tried this method:

{groupObject}.Members.Remove({entityObject} as DirectoryObject); await myGroup.UpdateAsync(); 

It is not interrupted, but the user is not removed from the group.

+5
source share
2 answers

I found a workaround. Perhaps this will help:

 public void RemoveUserFromGroup(Group group, User user) { var internalGroup = _activeDirectoryClient.Context.CreateQuery<GraphClient.Internal.Group>("groups/" + group.ObjectId).ToList().First(); var internalUser = _activeDirectoryClient.Context.CreateQuery<GraphClient.Internal.User>("users/" + user.ObjectId).ToList().First(); _activeDirectoryClient.Context.DeleteLink(internalGroup, "members", internalUser); _activeDirectoryClient.Context.SaveChanges(); } 
+13
source

I ran into a similar problem and was able to diagnose it. The problem that I think depends on how the group is extracted - are the members of the group included; you can use .Expand () clause for this.

For example, the following works:

 group = (Group)(await _activeDirectoryClient.Groups.Where(g => g.ObjectId == groupId).Expand(g => g.Members).ExecuteSingleAsync()); user = (User)(await _activeDirectoryClient.Users.Where(u => u.ObjectId == userId).ExecuteSingleAsync()); group.Members.Remove(user); await group.UpdateAsync(); 

Note, however, that the .Expand () operation is limited to 20 objects, so in most cases the solution from TomΓ‘Ε‘ is probably safer now.

+3
source

Source: https://habr.com/ru/post/1210121/


All Articles