/// <summary> /// validates verification code and reset password /// </summary> /// <param name="resetPasswordDto"></param> /// <returns></returns> public async Task ResetPasswordAsync(ResetPasswordDto resetPasswordDto) { CognitoUser user = new CognitoUser(resetPasswordDto.UserName, _appConfigInfo.AWSAppClientId, _userPool, _provider); try { await user.ConfirmForgotPasswordAsync(resetPasswordDto.VerificationCode, resetPasswordDto.NewPassword); } catch (ExpiredCodeException) { throw new CcsSsoException("INVALID_USERNAME_OR_CODE"); } catch (CodeMismatchException) { throw new CcsSsoException("INVALID_CODE"); } catch (InvalidParameterException) { throw new CcsSsoException("INVALID_PARAMETERS"); } catch (LimitExceededException) { throw new CcsSsoException("ERROR"); } }
internal async Task <CognitoUser> UpdatePassword(string username, string code, string newpassword) { AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials()); CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider); CognitoUser user = new CognitoUser(username, this.CLIENTAPP_ID, userPool, provider); await user.ConfirmForgotPasswordAsync(code, newpassword); return(user); }
/// <summary> /// Update Password /// </summary> /// <param name="username"></param> /// <param name="code"></param> /// <param name="newpassword"></param> /// <returns></returns> public async Task <CognitoUser> UpdatePassword(Real.UpdatePasswordRequest request) { AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials()); CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider); CognitoUser user = new CognitoUser(request.Username, this.CLIENTAPP_ID, userPool, provider); await user.ConfirmForgotPasswordAsync(request.TempPassword, request.NewPassword); return(user); }
//Step 2 in resetting a password //Sending new password along with code and all user data public async Task <CognitoContext> ResetPassword(string userName, string code, string newpassword) { try { CognitoUser user = new CognitoUser(userName, Keys.AWS_UsersPool_ClientID, UserPool, awsProvider); await user.ConfirmForgotPasswordAsync(code, newpassword); return(new CognitoContext(CognitoResult.Ok)); } catch (Exception e) { return(new CognitoContext(CognitoResult.Unknown, e.Message)); } }
public virtual async Task <AuthEventEnum> VerifyCodeAsync(string code) { if (CurrentAuthProcess == AuthProcessEnum.None) { return(AuthEventEnum.Alert_NoActiveAuthProcess); } if (CurrentChallenge != AuthChallengeEnum.Code) { return(AuthEventEnum.Alert_VerifyCalledButNoChallengeFound); } try { switch (CurrentAuthProcess) { case AuthProcessEnum.None: return(AuthEventEnum.Alert_InternalProcessError); case AuthProcessEnum.ResettingPassword: await CognitoUser.ConfirmForgotPasswordAsync(code, newPassword).ConfigureAwait(false); AuthChallengeList.Remove(AuthChallengeEnum.Code); return(await NextChallenge()); case AuthProcessEnum.SigningUp: var result = await providerClient.ConfirmSignUpAsync( new ConfirmSignUpRequest { ClientId = clientId, Username = login, ConfirmationCode = code }).ConfigureAwait(false); IsCodeVerified = true; AuthChallengeList.Remove(AuthChallengeEnum.Code); return(await NextChallenge()); case AuthProcessEnum.SigningIn: if (authFlowResponse == null) // authFlowResponse set during VerifyPassword { return(AuthEventEnum.Alert_InternalSignInError); } authFlowResponse = await CognitoUser.RespondToSmsMfaAuthAsync( new RespondToSmsMfaRequest() { SessionID = authFlowResponse.SessionID, MfaCode = code } ).ConfigureAwait(false); AuthChallengeList.Remove(AuthChallengeEnum.Code); return(await NextChallenge()); case AuthProcessEnum.UpdatingEmail: await CognitoUser.VerifyAttributeAsync("email", code).ConfigureAwait(false); IsCodeVerified = true; AuthChallengeList.Remove(AuthChallengeEnum.Code); return(await NextChallenge()); case AuthProcessEnum.UpdatingPhone: return(AuthEventEnum.Alert_InternalProcessError); default: return(AuthEventEnum.Alert_InternalProcessError); } } catch (InvalidPasswordException) { return(AuthEventEnum.Alert_PasswordFormatRequirementsFailed); } catch (TooManyRequestsException) { return(AuthEventEnum.Alert_TooManyAttempts); } catch (TooManyFailedAttemptsException) { return(AuthEventEnum.Alert_TooManyAttempts); } catch (NotAuthorizedException) { return(AuthEventEnum.Alert_NotAuthorized); } catch (UserNotFoundException) { return(AuthEventEnum.Alert_UserNotFound); } catch (UserNotConfirmedException) { return(AuthEventEnum.Alert_NotConfirmed); } catch (CodeMismatchException) { return(AuthEventEnum.Alert_VerifyFailed); } catch (AliasExistsException) { return(AuthEventEnum.Alert_AccountWithThatEmailAlreadyExists); } catch (Exception e) { Debug.WriteLine($"VerifyCode() threw an exception {e}"); CognitoUser = null; return(AuthEventEnum.Alert_Unknown); } }
public async Task ForgotPasswordConfirmation(String verificationCode, String newPassword) { await user.ConfirmForgotPasswordAsync(verificationCode, newPassword); }