private async Task <string> AddDkpAdminAsync(string pUsername, string pUserPool) { AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(RegionEndpoint.USEast2); AdminAddUserToGroupRequest vRequest = new AdminAddUserToGroupRequest { GroupName = ADMIN_GROUP, Username = pUsername, UserPoolId = pUserPool }; var vResponse = await provider.AdminAddUserToGroupAsync(vRequest); return(vResponse.HttpStatusCode.ToString()); }
public async Task UpdateUserGroup(string id, string groupName) { var groupsResponse = await provider.AdminListGroupsForUserAsync(new AdminListGroupsForUserRequest { Username = id, UserPoolId = Configurations.Cognito.CognitoPoolId, } ); var userAlreadyInGroup = false; if (groupsResponse.Groups.Count > 0) { foreach (var group in groupsResponse.Groups) { if (group.GroupName == groupName) { userAlreadyInGroup = true; continue; } else { await provider.AdminRemoveUserFromGroupAsync(new AdminRemoveUserFromGroupRequest { Username = id, UserPoolId = Configurations.Cognito.CognitoPoolId, GroupName = group.GroupName, }); } } } if (userAlreadyInGroup) { return; } var request = new AdminAddUserToGroupRequest { Username = id, UserPoolId = Configurations.Cognito.CognitoPoolId, GroupName = groupName, }; await provider.AdminAddUserToGroupAsync(request); }
public async Task AddUserToGroup(string Username, string GroupName) { AdminAddUserToGroupRequest request = new AdminAddUserToGroupRequest() { GroupName = GroupName, Username = Username, UserPoolId = GetUserPoolId(), }; AmazonCognitoIdentityProviderClient identityProvider = GetAmazonCognitoIdentity(); AdminAddUserToGroupResponse response = await identityProvider.AdminAddUserToGroupAsync(request); if (!response.HttpStatusCode.Equals(HttpStatusCode.OK)) { throw new WebApiException(response.HttpStatusCode, "add user to group failed"); } }
public async Task <ActionResult <string> > Register(UserVM user) { var cognito = new AmazonCognitoIdentityProviderClient(_region); var signUpRequest = new SignUpRequest { ClientId = _clientId, Password = user.Password, Username = user.Username }; var emailAttribute = new AttributeType { Name = "email", Value = user.Email }; signUpRequest.UserAttributes.Add(emailAttribute); var addToGroupRequest = new AdminAddUserToGroupRequest { GroupName = _defaultRole, Username = user.Username, UserPoolId = _poolId }; var signUpResponse = await cognito.SignUpAsync(signUpRequest); var addToGroupResponse = await cognito.AdminAddUserToGroupAsync(addToGroupRequest); if (signUpResponse.HttpStatusCode == HttpStatusCode.OK) { _userRepository.CreateUser(user); } return(Ok()); }
public async Task <ActionResult <string> > Register(User user) { var cognito = new AmazonCognitoIdentityProviderClient(_region); var request = new SignUpRequest { ClientId = _clientId, Password = user.Password, Username = user.Username }; var emailAttribute = new AttributeType { Name = "email", Value = user.Email }; request.UserAttributes.Add(emailAttribute); var response = await cognito.SignUpAsync(request); var groupResponse = await cognito.AdminAddUserToGroupAsync(new AdminAddUserToGroupRequest { GroupName = "Admin", Username = user.Username, UserPoolId = "us-west-2_TQaxeubl4" }); var confResponse = await cognito.AdminConfirmSignUpAsync(new AdminConfirmSignUpRequest { Username = user.Username, UserPoolId = "us-west-2_TQaxeubl4" }); return(Ok()); }