public void AddRemoveAADUserByOIDWithStorageKey() { // 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 = "27dbfced-5593-4756-98a3-913c39af7612", StorageKey = new Guid("9b71f216-4c4f-6b74-a911-efb0fa9c777f") }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); // // Part 2: get the user // ClientSampleHttpLogger.SetOperationName(this.Context, "GetUser-AddRemoveAADUserByOIDWithStorageKey"); newUser = graphClient.GetUserAsync(userDescriptor).Result; // // Part 3: remove the user // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser-AddRemoveAADUserByOIDWithStorageKey"); graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipState-AddRemoveAADUserByOIDWithStorageKey"); GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; try { if (membershipState.Active) { throw new Exception(); } } catch (Exception) { Context.Log("The deleted user is not disabled!"); } }
public void AddRemoveAADUserByUPN() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: add the AAD user // ClientSampleHttpLogger.SetOperationName(this.Context, "CreateUserAAD"); GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext { PrincipalName = "*****@*****.**" }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); // // Part 2: get the user // ClientSampleHttpLogger.SetOperationName(this.Context, "GetUserAAD"); newUser = graphClient.GetUserAsync(userDescriptor).Result; // // Part 3: remove the user // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUserAAD"); graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipStateAAD"); GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; try { if (membershipState.Active) { throw new Exception(); } } catch (Exception) { Context.Log("The deleted user is not disabled!"); } }
public void AddRemoveAADUserByOID() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: add the AAD user // ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOID"); GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b" }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); // // Part 2: get the user // ClientSampleHttpLogger.SetOperationName(this.Context, "GetUser-AddRemoveAADUserByOID"); newUser = graphClient.GetUserAsync(userDescriptor).Result; // // Part 3: remove the user // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser-AddRemoveAADUserByOID"); graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipState-AddRemoveAADUserByOID"); GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; try { if (membershipState.Active) { throw new Exception(); } } catch (Exception) { Context.Log("The deleted user is not disabled!"); } }
public void AddRemoveAADUserByUPN() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: add the AAD user // ClientSampleHttpLogger.SetOperationName(this.Context, "CreateUserAAD"); GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext { PrincipalName = "*****@*****.**" }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); // // Part 2: get the user // ClientSampleHttpLogger.SetOperationName(this.Context, "GetUserAAD"); //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 3: remove the user // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUserAAD"); graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user try { ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledUserAAD"); newUser = graphClient.GetUserAsync(userDescriptor).Result; if (!newUser.Disabled) { throw new Exception(); } } catch (Exception) { Context.Log("The deleted user is not disabled!"); } }
public void AddRemoveAADUserByOID() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: add the AAD user // ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOID"); GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b" }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); // // Part 2: 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 3: 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 AddRemoveAADUserByOIDWithVSID() { // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>(); // // Part 1: add the AAD user // ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithVSID"); GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b" /* TODO: Id = Guid.NewGuid() */ }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); // // Part 2: get the user // //newUser = graphClient.GetUserAsync(userDescriptor).Result; // // Part 3: 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!"); } }
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 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(); }