示例#1
0
        /// <summary>
        /// Confirms the user's new password using the confirmation code sent to them using
        /// an asynchronous call
        /// </summary>
        /// <param name="confirmationCode">The confirmation code sent to the suer</param>
        /// <param name="newPassword">The new desired password for the user</param>
        public virtual Task ConfirmForgotPasswordAsync(string confirmationCode, string newPassword)
        {
            ConfirmForgotPasswordRequest confirmResetPassRequest =
                CreateConfirmPasswordRequest(confirmationCode, newPassword);

            return(Provider.ConfirmForgotPasswordAsync(confirmResetPassRequest));
        }
示例#2
0
        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!"));
        }
示例#3
0
        /// <summary>
        /// Confirms the user's new password using the confirmation code sent to them using
        /// an asynchronous call
        /// </summary>
        /// <param name="confirmationCode">The confirmation code sent to the suer</param>
        /// <param name="newPassword">The new desired password for the user</param>
        public void ConfirmForgotPasswordAsync(string confirmationCode, string newPassword, AsyncCallback callback = null)
        {
            ConfirmForgotPasswordRequest confirmResetPassRequest =
                CreateConfirmPasswordRequest(confirmationCode, newPassword);


            Provider.ConfirmForgotPasswordAsync(confirmResetPassRequest, r => callback?.Invoke(new AsyncResult(r.Exception)));
        }
示例#4
0
        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);
             * }*/
        }
示例#5
0
        /// <summary>
        /// Inicia a recuperação de senha para um usuário
        /// </summary>
        /// <param name="forgotPasswordRequest">Informações para recuperação de senha</param>
        /// <returns>Sucesso</returns>
        public async Task ConfirmForgotPasswordAsync(
            ConfirmForgotPasswordRequest confirmForgotPasswordRequest)
        {
            _httpClient.DefaultRequestHeaders.Authorization = null;

            HttpResponseMessage response = await _httpClient.PostAsync(
                Endpoints.Auth.ConfirmForgotPassword_v1_0,
                confirmForgotPasswordRequest.ToStringContent()).ConfigureAwait(false);
            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
示例#6
0
        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();
        }
示例#7
0
        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));
        }
示例#8
0
        public async Task <IActionResult> ConfirmForgotPassword([FromBody] ConfirmForgotPasswordRequest request)
        {
            var user = await DatabaseContext.Users
                       .FirstOrDefaultAsync(u => u.PasswordRecoveryCode != null && u.PasswordRecoveryCode == request.PasswordRecoveryCode);

            if (user == null)
            {
                return(BadRequest("Password recovery code is not correct"));
            }
            await _authenticationService.ChangePassword(user, request.NewPassword);

            return(Ok());
        }
示例#9
0
        private ConfirmForgotPasswordRequest CreateConfirmPasswordRequest(string confirmationCode, string newPassword)
        {
            ConfirmForgotPasswordRequest confirmResetPassRequest = new ConfirmForgotPasswordRequest()
            {
                Username         = Username,
                ClientId         = ClientID,
                Password         = newPassword,
                ConfirmationCode = confirmationCode
            };

            if (!string.IsNullOrEmpty(SecretHash))
            {
                confirmResetPassRequest.SecretHash = SecretHash;
            }

            return(confirmResetPassRequest);
        }
        /// <summary>
        /// Resets the <paramref name="user"/>'s password to the specified <paramref name="newPassword"/> after
        /// validating the given password reset <paramref name="token"/>.
        /// </summary>
        /// <param name="user">The user whose password should be reset.</param>
        /// <param name="token">The password reset token to verify.</param>
        /// <param name="newPassword">The new password to set if reset token verification succeeds.</param>
        /// <returns>
        /// The <see cref="Task"/> that represents the asynchronous operation, containing the <see cref="IdentityResult"/>
        /// of the operation.
        /// </returns>
        public Task ConfirmForgotPassword(string userID, string token, string newPassword, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var request = new ConfirmForgotPasswordRequest
            {
                Username         = userID,
                ClientId         = ClientID,
                ConfirmationCode = token,
                Password         = newPassword,
            };

            if (!string.IsNullOrEmpty(ClientSecret))
            {
                request.SecretHash = CognitoAuthHelper.GetUserPoolSecretHash(userID, ClientID, ClientSecret);
            }

            return(Provider.ConfirmForgotPasswordAsync(request, cancellationToken));
        }
示例#11
0
        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);
            }
        }
 public void ConfirmForgotPasswordAsync(ConfirmForgotPasswordRequest request, AmazonServiceCallback <ConfirmForgotPasswordRequest, ConfirmForgotPasswordResponse> callback, AsyncOptions options = null)
 {
     throw new System.NotImplementedException();
 }