Exemple #1
0
        public void ResendConfirmation(ConfirmationResendRequest confirmationResendRequest)
        {
            ResendConfirmationCodeRequest resendConfirmationCodeRequest = new ResendConfirmationCodeRequest()
            {
                ClientId = _connectionInfo.ClientId,
                Username = confirmationResendRequest.Email
            };

            try
            {
                _provider.ResendConfirmationCodeAsync(resendConfirmationCodeRequest).Wait();
            }
            catch (Exception e)
            {
                LoggingHandler.LogError(e.Message);
                LoggingHandler.LogError(e.StackTrace);
                throw;
            }
        }
Exemple #2
0
        public async Task <IActionResult> Resend(UserToResendRequest userToResendRequest)
        {
            try
            {
                AmazonCognitoIdentityProviderClient _client        = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials(), RegionEndpoint.USEast1);
                ResendConfirmationCodeRequest       confirmRequest = new ResendConfirmationCodeRequest()
                {
                    Username = userToResendRequest.Email,
                    ClientId = _config.GetSection("AWS").GetSection("UserPoolClientId").Value
                };

                await _client.ResendConfirmationCodeAsync(confirmRequest);

                return(Ok(new CommonResponse(ErrorCodes.SUCCESS)));
            }
            catch (AmazonServiceException e)
            {
                return(BadRequest(new CommonResponse(ErrorCodes.ERROR, e.Message)));
            }
        }
Exemple #3
0
        public async Task <Tuple <int, string> > ResendConfirmationCodeAsync(string username)
        {
            try
            {
                var codeRequest = new ResendConfirmationCodeRequest
                {
                    Username = username,
                    ClientId = Constants.POOL_CLIENT_ID
                };

                var codeResult = await client.ResendConfirmationCodeAsync(codeRequest);

                if (codeResult.HttpStatusCode == HttpStatusCode.OK)
                {
                    return(Tuple.Create <int, string>(1, "Verification code request sent!"));
                }
            }
            catch (Exception e)
            {
                return(Tuple.Create <int, string>(0, e.Message));
            }
            return(Tuple.Create <int, string>(-1, "Unable to send confirmation code!"));
        }
Exemple #4
0
        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);
            }
        }