public async Task <Tuple <bool, string> > ConfirmNewPassowrdAsync(string username, string password, string code) { try { var passwordRequest = new ConfirmForgotPasswordRequest { ClientId = Constants.POOL_CLIENT_ID, Username = username, Password = password, ConfirmationCode = code }; var response = await client.ConfirmForgotPasswordAsync(passwordRequest); if (response.HttpStatusCode == HttpStatusCode.OK) { return(Tuple.Create <bool, string>(true, "New password set successfully!")); } } catch (UserNotConfirmedException e) { Console.WriteLine(e.Message); } catch (NotAuthorizedException e) { Console.WriteLine(e.Message); } catch (Exception e) { return(Tuple.Create <bool, string>(false, e.Message)); } return(Tuple.Create <bool, string>(false, "Could not set new passowrd!")); }
public override async Task <Unit> Handle(CognitoForgotPasswordConfirmCommand 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 confirm reset password."); } using (var provider = new AmazonCognitoIdentityProviderClient(AwsId, AwsKey, RegionEndpoint.USEast1)) { var reset = await provider.ConfirmForgotPasswordAsync(new ConfirmForgotPasswordRequest { ClientId = UserGroupClientId, Password = request.Password, ConfirmationCode = request.Code, Username = user.LegacyId.ToString() }, cancellationToken); if (reset.HttpStatusCode != HttpStatusCode.OK) { throw new Exception("Failed to reset password. Status Code: " + reset.HttpStatusCode); } return(Unit.Value); } }
public static async Task ResetPwdForgot(string _username, string _code, int _clientid, string _newPassword) { using (var cognito = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), Constants.REGION)) { ConfirmForgotPasswordRequest confirmForgotPasswordRequest = new ConfirmForgotPasswordRequest() { Username = _username, ClientId = Constants.CLIENTAPP_ID, Password = _newPassword, SecretHash = CognitoHashCalculator.GetSecretHash(_username, Constants.CLIENTAPP_ID, Constants.NeokySecret), ConfirmationCode = _code }; ConfirmForgotPasswordResponse confirmForgotPasswordResponse = new ConfirmForgotPasswordResponse(); try { confirmForgotPasswordResponse = await cognito.ConfirmForgotPasswordAsync(confirmForgotPasswordRequest).ConfigureAwait(false); ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_CONFIRMED); } catch (CodeMismatchException) { // Username Unknown or Code Expired ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_CODE_MISMATCH_KO); } catch (ExpiredCodeException) { // Username Unknown or Code Expired ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_CODE_EXPIRED_KO); } catch (Exception e) { HandleForgotPwdExceptions(e, _clientid); } } // Initiate Forgot Password Modification By Code /*try * { * // Lunch myUser Change Forgotten Pwd * //await Server.clients[_clientid].myUser.ConfirmForgotPasswordAsync(_code, _newPassword); * await Server.cognitoManagerServer.provider. * ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_CONFIRMED); * * // Authenticate & Check Challenge. * * } * catch (Exception e) * { * HandleExceptions(e, _clientid, Constants.SCENE_FORGOT_PASSWORD); * }*/ }
public void ConfirmResetPassword(ResetPasswordQueryParams resetPasswordQueryParams) { ConfirmForgotPasswordRequest cfpRequest = new ConfirmForgotPasswordRequest { ClientId = _connectionInfo.ClientId, Username = resetPasswordQueryParams.Email, Password = resetPasswordQueryParams.Password, ConfirmationCode = resetPasswordQueryParams.Code }; _provider.ConfirmForgotPasswordAsync(cfpRequest).Wait(); }
public async Task <ConfirmForgotPasswordResponse> ConfirmForgotPasswordAsync( IConfirmForgotPasswordCredentials confirmForgotPasswordCredentialsImp, CancellationToken cancellationToken = new CancellationToken()) { var confirmForgotPasswordRequest = new ConfirmForgotPasswordRequest(); confirmForgotPasswordRequest.Username = confirmForgotPasswordCredentialsImp.UserName; confirmForgotPasswordRequest.ClientId = _clientId; confirmForgotPasswordRequest.Password = confirmForgotPasswordCredentialsImp.Password; confirmForgotPasswordRequest.ConfirmationCode = confirmForgotPasswordCredentialsImp.ConfirmationCode; return(await _client.ConfirmForgotPasswordAsync(confirmForgotPasswordRequest, cancellationToken)); }
public new async Task <bool> ResetPasswordAsync(string username, string code, string password) { var forgotPasswordRequest = new ConfirmForgotPasswordRequest() { ClientId = _clientId, Username = username, ConfirmationCode = code, Password = password }; try { var result = await _client.ConfirmForgotPasswordAsync(forgotPasswordRequest); return(true); } catch (Exception e) { return(false); } }