private UserType FindDestinationUser(dynamic input, string email) { //Find existing user var response = _client.ListUsersAsync(new ListUsersRequest { Filter = $"email=\"{email}\"", Limit = 1, UserPoolId = input.userPoolId }).Result; //Handle bad status code if (response.HttpStatusCode != HttpStatusCode.OK) { Console.WriteLine($"Failed to search for users:{response.HttpStatusCode}"); throw new PreSignupTriggerException("Unable to search for existing account to pair with"); } //No user found. Since auto sign-up is not allowed on this pool, throw an exception if (response.Users.Count == 0) { Console.WriteLine($"No existing users found with email:{email}"); throw new PreSignupTriggerException("No existing user with same email found"); } return(response.Users[0]); }
private async Task <object> GetAllUsersAsync(string pUserPool) { AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(RegionEndpoint.USEast2); ListUsersRequest vRequest = new ListUsersRequest { UserPoolId = pUserPool }; ListUsersInGroupResponse vGroupResponse = await provider.ListUsersInGroupAsync(new ListUsersInGroupRequest { GroupName = ADMIN_GROUP, UserPoolId = pUserPool }); ListUsersResponse vResponse = await provider.ListUsersAsync(vRequest); var vReturn = new { Admins = vGroupResponse.Users, AllUsers = vResponse.Users }; return(vReturn); }
public async Task <UserType> FindUserByEmail(string email) { var request = new ListUsersRequest { UserPoolId = Configurations.Cognito.CognitoPoolId, Filter = $"email = \"{email.ToLower()}\"", }; var usersResponse = await provider.ListUsersAsync(request); if (usersResponse.Users.Count > 0) { var user = usersResponse.Users.First(); // dont return passcode property to client user.Attributes.Remove(user.Attributes.Find(x => x.Name == "custom:authChallenge")); return(user); } return(null); }
public override async Task <User> Handle(CognitoGetUserByEmailQuery request, CancellationToken cancellationToken) { using (var provider = new AmazonCognitoIdentityProviderClient(AwsId, AwsKey, RegionEndpoint.USEast1)) { var res = await provider.ListUsersAsync(new ListUsersRequest { Filter = $"email = \"{request.Email}\"", UserPoolId = UserPoolId }); return(res.Users.Select(t => ParseToUser(t.Attributes)).FirstOrDefault()); } }
private async Task ListUsers(Func <IEnumerable <User>, Task> action, string paginationToken = null) { using (var provider = new AmazonCognitoIdentityProviderClient(AwsId, AwsKey, RegionEndpoint.USEast1)) { var res = await provider.ListUsersAsync(new ListUsersRequest { UserPoolId = UserPoolId, PaginationToken = paginationToken }); var users = res.Users.Select(t => ParseToUser(t.Attributes)); await action(users); if (string.IsNullOrEmpty(res.PaginationToken)) { return; } await ListUsers(action, res.PaginationToken); } }