public virtual async Task <AuthEventEnum> VerifyNewPasswordAsync(string newPassword) { if (CurrentChallenge != AuthChallengeEnum.NewPassword) { return(AuthEventEnum.Alert_VerifyCalledButNoChallengeFound); } if (!CheckNewPasswordFormat(newPassword)) { return(AuthEventEnum.Alert_PasswordFormatRequirementsFailed); } try { switch (CurrentAuthProcess) { case AuthProcessEnum.SigningUp: authFlowResponse = await CognitoUser.RespondToNewPasswordRequiredAsync( new RespondToNewPasswordRequiredRequest() { SessionID = authFlowResponse.SessionID, NewPassword = newPassword } ).ConfigureAwait(false); this.newPassword = newPassword; AuthChallengeList.Remove(AuthChallengeEnum.NewPassword); return(await NextChallenge()); case AuthProcessEnum.ResettingPassword: this.newPassword = newPassword; CognitoUser user = new CognitoUser(login, clientId, userPool, providerClient); await user.ForgotPasswordAsync().ConfigureAwait(false); AuthChallengeList.Remove(AuthChallengeEnum.NewPassword); AuthChallengeList.Add(AuthChallengeEnum.Code); return(await NextChallenge()); case AuthProcessEnum.UpdatingPassword: this.newPassword = newPassword; AuthChallengeList.Remove(AuthChallengeEnum.NewPassword); return(await NextChallenge()); 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 (Exception e) { Debug.WriteLine($"VerifyPassword() threw an exception {e}"); CognitoUser = null; return(AuthEventEnum.Alert_Unknown); } }
internal async Task <CognitoUser> ResetPassword(string username) { 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.ForgotPasswordAsync(); return(user); }
//Step 1 in resetting a password //Sending a reset request to send a verification code public async Task <CognitoContext> ForgotPassword(string userName) { try { CognitoUser user = new CognitoUser(userName, Keys.AWS_UsersPool_ClientID, UserPool, awsProvider); await user.ForgotPasswordAsync(); return(new CognitoContext(CognitoResult.Ok)); } catch (Exception e) { return(new CognitoContext(CognitoResult.Unknown, e.Message)); } //in case forgot password }
public async Task <CognitoContext> ForgotPassword(string userName) { try { CognitoUserPool userPool = new CognitoUserPool(Constants.COGNITO_USER_POOL_ID, Constants.COGNITO_CLIENT_ID, CognitoIdentityProviderClient); CognitoUser user = new CognitoUser(userName, Constants.COGNITO_CLIENT_ID, CognitoUserPool, CognitoIdentityProviderClient); await user.ForgotPasswordAsync(); return(new CognitoContext(CognitoResult.Ok)); } catch (Exception e) { Console.WriteLine($"ForgotPassword() threw an exception {e}"); } return(new CognitoContext(CognitoResult.Unknown)); }
public async Task <CognitoContext> ForgotPassword(string userName, string code) { try { var provider = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), RegionEndpoint.USWest2); CognitoUserPool userPool = new CognitoUserPool(PoolId, ClientId, provider); CognitoUser user = new CognitoUser(userName, ClientId, userPool, provider); await user.ForgotPasswordAsync(); return(new CognitoContext(CognitoResult.Ok)); } catch (Exception e) { Console.WriteLine("InputGem", "Boo, an exception!", e); } return(new CognitoContext(CognitoResult.Unknown)); }
public async Task <RequestResult> ResetPassword(string username) { RequestResult result = new RequestResult(); try { CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider); CognitoUser user = new CognitoUser(username, this.CLIENTAPP_ID, userPool, provider); await user.ForgotPasswordAsync(); result.Data = user; result.Status = true; result.Message = "Password Updated Successfully"; } catch (Exception ex) { result.Status = false; result.Message = ex.Message; } return(result); }
public virtual async Task <AuthEventEnum> ResendCodeAsync() { if (CurrentChallenge != AuthChallengeEnum.Code) { return(AuthEventEnum.Alert_InvalidCallToResendAsyncCode); } try { switch (CurrentAuthProcess) { case AuthProcessEnum.UpdatingEmail: // We need to re-submit the email change request for Amazon to resend the code if (!IsSignedIn) { return(AuthEventEnum.Alert_NeedToBeSignedIn); } //// Get the current values on the server. //// This step may throw an exception in RefreshUserDetailsAsync. There seems to be //// no way to recover from this other than retry or abandon the process. Let the //// calling class figure out what is right for their usecase. //AuthEventEnum refreshUserDetailsResult = await RefreshUserDetailsAsync().ConfigureAwait(false); //if (refreshUserDetailsResult != AuthEventEnum.Alert_RefreshUserDetailsDone) // return AuthEventEnum.Alert_CantRetrieveUserDetails; //// make sure the values are different //if (this.email.Equals(newEmail)) //todo - check //{ // return AuthEventEnum.Alert_EmailAddressIsTheSame; //} //// Update the user email on the server //// This may throw an exception in the UpdateAttributesAsync call. //var attributes = new Dictionary<string, string>() { { "email", newEmail } }; //// Cognito sends a auth code when the Email attribute is changed //await CognitoUser.UpdateAttributesAsync(attributes).ConfigureAwait(false); await CognitoUser.GetAttributeVerificationCodeAsync("email").ConfigureAwait(false); return(AuthEventEnum.VerificationCodeSent); case AuthProcessEnum.ResettingPassword: // we need to issue the ForgotPassword again to resend code CognitoUser user = new CognitoUser(login, clientId, userPool, providerClient); await user.ForgotPasswordAsync().ConfigureAwait(false); return(AuthEventEnum.AuthChallenge); case AuthProcessEnum.SigningUp: _ = await providerClient.ResendConfirmationCodeAsync( new ResendConfirmationCodeRequest { ClientId = clientId, Username = login }).ConfigureAwait(false); return(AuthEventEnum.AuthChallenge); default: return(AuthEventEnum.Alert_InvalidCallToResendAsyncCode); } } catch (Exception e) { Debug.WriteLine($"SignUp() threw an exception {e}"); return(AuthEventEnum.Alert_Unknown); } }
public async Task ForgotPassowrd() { await user.ForgotPasswordAsync(); }