public void AddRemoveAADGroupByOIDAsMemberOfVSTSGroup() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: create the VSTS group // ClientSampleHttpLogger.SetOperationName(this.Context, "CreateVSTSGroup"); GraphGroupCreationContext createVSTSGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; GraphGroup newVSTSGroup = graphClient.CreateGroupAsync(createVSTSGroupContext).Result; IEnumerable <VisualStudio.Services.Common.SubjectDescriptor> parentGroup = new List <VisualStudio.Services.Common.SubjectDescriptor>() { newVSTSGroup.Descriptor }; string vstsGroupDescriptor = newVSTSGroup.Descriptor; // // Part 2: add the AAD group // GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { OriginId = "7dee3381-2ec2-41c2-869a-7afe9b574095" }; ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDAsMember"); GraphGroup addedAADGroup = graphClient.CreateGroupAsync(addAADGroupContext, null, parentGroup).Result; string aadGroupDescriptor = addedAADGroup.Descriptor; Context.Log("New group created! ID: {0}", aadGroupDescriptor); // // Part 3: get the AAD group // ClientSampleHttpLogger.SetOperationName(this.Context, "GetGroup-AddRemoveAADGroupByOIDAsMemberOfVSTSGroup"); GraphGroup newGroup = graphClient.GetGroupAsync(aadGroupDescriptor).Result; // // Part 4: remove the AAD group // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteAADGroup-AddRemoveAADGroupByOIDAsMemberOfVSTSGroup"); graphClient.DeleteGroupAsync(aadGroupDescriptor).SyncResult(); // // Part 5: delete the VSTS group // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteVSTSGroup-AddRemoveAADGroupByOIDAsMemberOfVSTSGroup"); graphClient.DeleteGroupAsync(vstsGroupDescriptor).SyncResult(); }
public void CreateDeleteProjectVSTSGroup() { // Get the client VssConnection connection = Context.Connection; // // Part 1: get the project id // ClientSampleHttpLogger.SetOperationName(this.Context, "GetProjectId"); ProjectHttpClient projectClient = connection.GetClient <ProjectHttpClient>(); string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; TeamProject project = projectClient.GetProject(projectName, includeCapabilities: true, includeHistory: true).Result; Guid projectId = project.Id; // // Part 2: get the project scope descriptor // ClientSampleHttpLogger.SetOperationName(this.Context, "GetProjectScopeDescriptor"); GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); GraphDescriptorResult projectDescriptor = graphClient.GetDescriptorAsync(projectId).Result; // // Part 3: create a group at the project level // ClientSampleHttpLogger.SetOperationName(this.Context, "CreateGroupInProject"); GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Project Developers-" + Guid.NewGuid(), Description = "Group at project level created via client library" }; GraphGroup newGroup = graphClient.CreateGroupAsync(createGroupContext, projectDescriptor.Value).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); // // Part 4: delete the group // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteGroup"); graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group (should result in an exception) ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup"); try { newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; } catch (Exception e) { Context.Log("Unable to get the deleted group:" + e.Message); } }
public void CreateUpdateDeleteVSTSGroup() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: create a group at the account level // ClientSampleHttpLogger.SetOperationName(this.Context, "CreateGroup"); GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; GraphGroup newGroup = graphClient.CreateGroupAsync(createGroupContext).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); // // Part 2: update the description attribute for the group // ClientSampleHttpLogger.SetOperationName(this.Context, "UpdateGroup"); Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchDocument patchDocument = VssJsonPatchDocumentFactory.ConstructJsonPatchDocument(VisualStudio.Services.WebApi.Patch.Operation.Replace, Constants.GroupUpdateFields.Description, "Updated description"); GraphGroup updatedGroup = graphClient.UpdateGroupAsync(groupDescriptor, patchDocument).Result; string groupDescription = updatedGroup.Description; Context.Log("Updated group description: {0}", groupDescription); // // Part 3: delete the group // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteGroup"); graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group (should result in an exception) try { ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup"); newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; } catch (Exception e) { Context.Log("Unable to get the deleted group:" + e.Message); } }
public void LookupSubject() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: add the AAD user // ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithStorageKey"); GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b", StorageKey = Guid.NewGuid() }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); // // Part 2: add the AAD group // ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDWithStorageKey"); GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { OriginId = "f0d20172-7b96-42f6-9436-941433654b48", StorageKey = Guid.NewGuid() }; GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); // // Part 3: lookup subjects // GraphSubjectLookup subjectLookup = new GraphSubjectLookup(new[] { new GraphSubjectLookupKey(newGroup.Descriptor), new GraphSubjectLookupKey(newUser.Descriptor) }); ClientSampleHttpLogger.SetOperationName(this.Context, "LookupSubjects"); IReadOnlyDictionary <SubjectDescriptor, GraphSubject> lookups = graphClient.LookupSubjectsAsync(subjectLookup).Result; }
public void AddRemoveAADGroupByOIDWithStorageKey() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: add the AAD group // ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDWithStorageKey"); GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { OriginId = "f0d20172-7b96-42f6-9436-941433654b48", StorageKey = Guid.NewGuid() //TODO: Remove Hard coded GUID StorageKey = new Guid("fc24f8cc-aed7-4bd4-be08-052d7fd30c39") }; GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); // // Part 2: get the group // ClientSampleHttpLogger.SetOperationName(this.Context, "GetGroup-AddRemoveAADGroupByOIDWithStorageKey"); newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; // // Part 3: remove the group // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteGroup-AddRemoveAADGroupByOIDWithStorageKey"); graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group (should result in an exception) ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup-AddRemoveAADGroupByOIDWithStorageKey"); try { newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; } catch (Exception e) { Context.Log("Unable to get the removed group:" + e.Message); } }
public void AddRemoveAADGroupByOID() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: add the AAD group // ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOID"); GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { OriginId = "77ed2186-aaf6-4299-ac9e-37ba282c2b95" }; GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); // // Part 2: get the group // ClientSampleHttpLogger.SetOperationName(this.Context, "GetGroup-AddRemoveAADGroupByOID"); newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; // // Part 3: remove the group // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteGroup-AddRemoveAADGroupByOID"); graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group (should result in an exception) ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup-AddRemoveAADGroupByOID"); try { newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; } catch (Exception e) { Context.Log("Unable to get the removed group:" + e.Message); } }
public void AddRemoveAADGroupByOIDWithVSID() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: add the AAD group // ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDWithVSID"); GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { OriginId = "f0d20172-7b96-42f6-9436-941433654b48", Id = Guid.NewGuid() }; GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); // // Part 2: get the group // newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; // // Part 3: remove the group // graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group (should result in an exception) try { newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; } catch (Exception e) { Context.Log("Unable to get the removed group:" + e.Message); } }
public void AddRemoveAADGroupMembership() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: create a group at the account level // GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; GraphGroup parentGroup = graphClient.CreateGroupAsync(createGroupContext).Result; string parentGroupDescriptor = parentGroup.Descriptor; Context.Log("New group created! ID: {0}", parentGroupDescriptor); // // Part 2: add the AAD group // GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { OriginId = "a42aad15-d654-4b16-9309-9ee34d5aacfb" }; GraphGroup aadGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; string aadGroupDescriptor = aadGroup.Descriptor; Context.Log("AAD group added! ID: {0}", aadGroupDescriptor); // // Part 3: Make the AAD group a member of the VSTS 'Developers' group // ClientSampleHttpLogger.SetOperationName(this.Context, "CreateMembershipAADGroup"); GraphMembership graphMembership = graphClient.AddMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).Result; // // Part 4: get the membership // ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipAADGroup"); graphMembership = graphClient.GetMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).Result; // // Part 5: Check to see if the AAD group is a member of the VSTS 'Developers' group // ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipAADGroup"); graphClient.CheckMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); // // Part 6: Get every group the subject(AAD group) is a member of // ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsAADGroupDown"); List <GraphMembership> membershipsForUser = graphClient.GetMembershipsAsync(aadGroupDescriptor).Result; // // Part 7: Get every member of the VSTS 'Developers' group // ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsAADGroupUp"); List <GraphMembership> membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum // // Part 8: Remove member from the group // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteMembershipAADGroup"); graphClient.RemoveMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); try { graphClient.CheckMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); } catch (Exception e) { Context.Log("AAD Group is no longer a member of the group:" + e.Message); } // // Part 9: delete the groups // graphClient.DeleteGroupAsync(aadGroupDescriptor).SyncResult(); graphClient.DeleteGroupAsync(parentGroupDescriptor).SyncResult(); }
public void AddRemoveUserMembership() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: create a group at the account level // GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; GraphGroup newGroup = graphClient.CreateGroupAsync(createGroupContext).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); // // Part 2: add the user // GraphUserCreationContext addUserContext = new GraphUserPrincipalNameCreationContext { PrincipalName = "*****@*****.**" }; GraphUser newUser = graphClient.CreateUserAsync(addUserContext).Result; string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); // // Part 3: Make the user a member of the group // ClientSampleHttpLogger.SetOperationName(this.Context, "CreateMembershipUser"); GraphMembership graphMembership = graphClient.AddMembershipAsync(userDescriptor, groupDescriptor).Result; // // Part 4: get the membership // ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipUser"); graphMembership = graphClient.GetMembershipAsync(userDescriptor, groupDescriptor).Result; // // Part 5: Check to see if the user is a member of the group // ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipUser"); graphClient.CheckMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); // // Part 6: Get every group the subject(user) is a member of // ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsUserUp"); List <GraphMembership> membershipsForUser = graphClient.GetMembershipsAsync(userDescriptor).Result; // // Part 7: Get every member of the group // ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsGroupDown"); List <GraphMembership> membershipsOfGroup = graphClient.GetMembershipsAsync(groupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum // // Part 8: Remove member from the group // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteMembershipUser"); graphClient.RemoveMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); try { graphClient.CheckMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); } catch (Exception e) { Context.Log("User is no longer a member of the group:" + e.Message); } // // Part 9: delete the group // graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // // Part 10: remove the user graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // // Try to get the deleted user try { newUser = graphClient.GetUserAsync(userDescriptor).Result; if (!newUser.Disabled) { throw new Exception(); } } catch (Exception) { Context.Log("The deleted user is not disabled!"); } }
public void AddRemoveAADUserByUPNToGroup() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: create a group at the account level // GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; GraphGroup newVSTSGroup = graphClient.CreateGroupAsync(createGroupContext).Result; IEnumerable <VisualStudio.Services.Common.SubjectDescriptor> parentGroup = new List <VisualStudio.Services.Common.SubjectDescriptor>() { newVSTSGroup.Descriptor }; string groupDescriptor = newVSTSGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); // // Part 2: add the AAD user // ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDAsMember"); GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext { PrincipalName = "*****@*****.**" }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext, parentGroup).Result; string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); // // Part 3: get the user // ClientSampleHttpLogger.SetOperationName(this.Context, "GetUser-AddRemoveAADUserByUPNToGroup"); newUser = graphClient.GetUserAsync(userDescriptor).Result; // // Part 4: remove the user // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser-AddRemoveAADUserByUPNToGroup"); graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipState-AddRemoveAADUserByUPNToGroup"); GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; try { if (membershipState.Active) { throw new Exception(); } } catch (Exception) { Context.Log("The deleted user is not disabled!"); } // Part 5: remove the group graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipStateAADGroup"); membershipState = graphClient.GetMembershipStateAsync(groupDescriptor).Result; try { if (membershipState.Active) { throw new Exception(); } } catch (Exception) { Context.Log("The deleted group is not disabled!"); } }
public void AddRemoveVSTSGroupMembership() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: create a group at the account level // ClientSampleHttpLogger.SetOperationName(this.Context, "CreateVSTSGroup-AddRemoveVSTSGroupMembership"); GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; GraphGroup parentGroup = graphClient.CreateGroupAsync(createGroupContext).Result; string parentGroupDescriptor = parentGroup.Descriptor; Context.Log("New group created! ID: {0}", parentGroupDescriptor); // // Part 2: create a second group at the account level // ClientSampleHttpLogger.SetOperationName(this.Context, "AddUserToGroup-AddRemoveVSTSGroupMembership"); createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Contractors", Description = "Child group created via client library" }; GraphGroup childGroup = graphClient.CreateGroupAsync(createGroupContext).Result; string childGroupDescriptor = childGroup.Descriptor; Context.Log("New group created! ID: {0}", childGroupDescriptor); // // Part 3: Make the 'Contractors' group a member of the 'Developers' group // ClientSampleHttpLogger.SetOperationName(this.Context, "CreateMembershipVSTSGroup"); GraphMembership graphMembership = graphClient.AddMembershipAsync(childGroupDescriptor, parentGroupDescriptor).Result; // // Part 4: get the membership // ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipVSTSGroup"); graphMembership = graphClient.GetMembershipAsync(childGroupDescriptor, parentGroupDescriptor).Result; // // Part 5: Check to see if the 'Contractors' group is a member of the 'Developers' group // ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipExistenceVSTSGroup"); graphClient.CheckMembershipExistenceAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); // // Part 6: Get every group the subject('Contractors') is a member of // ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsVSTSGroupUp"); List <GraphMembership> membershipsForUser = graphClient.ListMembershipsAsync(childGroupDescriptor).Result; // // Part 7: Get every member of the 'Developers' group // ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsVSTSGroupDown"); List <GraphMembership> membershipsOfGroup = graphClient.ListMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down).Result; // // Part 8: Remove member from the group // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteMembershipVSTSGroup"); graphClient.RemoveMembershipAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); try { ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipExistenceVSTSGroupDeleted"); graphClient.CheckMembershipExistenceAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); } catch (Exception e) { Context.Log("'Contractors' is no longer a member of the group:" + e.Message); } // // Part 9: delete the groups // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteChildGroup-AddRemoveVSTSGroupMembership"); graphClient.DeleteGroupAsync(childGroupDescriptor).SyncResult(); ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteParentGroup-AddRemoveVSTSGroupMembership"); graphClient.DeleteGroupAsync(parentGroupDescriptor).SyncResult(); }
public void AddRemoveAADUserByUPNToGroup() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: create a group at the account level // GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; GraphGroup newVSTSGroup = graphClient.CreateGroupAsync(createGroupContext).Result; IEnumerable <VisualStudio.Services.Common.SubjectDescriptor> parentGroup = new List <VisualStudio.Services.Common.SubjectDescriptor>() { newVSTSGroup.Descriptor }; string groupDescriptor = newVSTSGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); // // Part 2: add the AAD user // ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDAsMember"); GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext { PrincipalName = "*****@*****.**" }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext, parentGroup).Result; string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); // // Part 3: get the user // //newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\[email protected]' could not be found."} // // Part 4: remove the user // graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user try { newUser = graphClient.GetUserAsync(userDescriptor).Result; // TODO: if (!newUser.Disabled) throw new Exception(); } catch (Exception) { Context.Log("The deleted user is not disabled!"); } // Part 5: remove the group graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); }