public override async Task <Unit> Handle(CognitoFormatPasswordCommand request, CancellationToken cancellationToken) { var user = await _mediator.Send(new CognitoGetUserByEmailQuery { Email = request.Email }, cancellationToken); if (user == null) { throw new Exception("User not found by email: " + request.Email + ". Unable to reset password."); } using (var provider = new AmazonCognitoIdentityProviderClient(AwsId, AwsKey, RegionEndpoint.USEast1)) { if (!user.IsEmailVerified) { await provider.AdminUpdateUserAttributesAsync(new AdminUpdateUserAttributesRequest { UserAttributes = new List <AttributeType> { new AttributeType { Name = "email_verified", Value = "true" } }, Username = user.LegacyId.ToString(), UserPoolId = UserPoolId }, cancellationToken); } await provider.ForgotPasswordAsync(new ForgotPasswordRequest { ClientId = UserGroupClientId, Username = user.LegacyId.ToString() }, cancellationToken); } return(Unit.Value); }
public void ResetPassword(ResetPasswordQueryParams resetPasswordQueryParams) { ForgotPasswordRequest fpRequest = new ForgotPasswordRequest { ClientId = _connectionInfo.ClientId, Username = resetPasswordQueryParams.Email }; _provider.ForgotPasswordAsync(fpRequest).Wait(); }
public async Task ForgotPasswordAsync(string username) { try { CurrentUsername = username; var passowrdRequest = new ForgotPasswordRequest { Username = username, ClientId = Constants.POOL_CLIENT_ID }; var response = await client.ForgotPasswordAsync(passowrdRequest); } catch (UserNotConfirmedException e) { Console.WriteLine(e.Message); } catch (NotAuthorizedException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } }
public async Task <bool> SendForgotPasswordEmailAsync(string username) { var forgotPasswordRequest = new ForgotPasswordRequest() { ClientId = _clientId, Username = username }; try { var result = await _client.ForgotPasswordAsync(forgotPasswordRequest); return(true); } catch (Exception e) { return(false); } }
public static async Task ClientForgotPwdRequest(string _username, int _clientid) { using (var cognito = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), Constants.REGION)) { ForgotPasswordRequest ForgotPasswordRequest = new ForgotPasswordRequest() { Username = _username, ClientId = Constants.CLIENTAPP_ID, SecretHash = CognitoHashCalculator.GetSecretHash(_username, Constants.CLIENTAPP_ID, Constants.NeokySecret), }; ForgotPasswordResponse ForgotPasswordResponse = new ForgotPasswordResponse(); try { Console.WriteLine("SignInClients.cs | ForgotPasswordAsync Sending"); ForgotPasswordResponse = await cognito.ForgotPasswordAsync(ForgotPasswordRequest).ConfigureAwait(false); Console.WriteLine("SignInClients.cs | ForgotPasswordAsync OK"); ServerSend.ClientForgotPasswordStatus(_clientid, Constants.NEW_CODE_SEND_EMAIL); } catch (ExpiredCodeException) { // Username Unknown or Code Expired ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_CODE_EXPIRED_KO); } catch (Exception e) { Console.WriteLine("SignInClients.cs | My User ClientForgotPwdRequest Failed"); switch (e.GetType().ToString()) { default: Console.WriteLine("SignInClients.cs | Unknown Exception | " + e.GetType().ToString() + " | " + e); //ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_KO); break; } } } }