public async Task <IActionResult> OnPostAsync(bool rememberMe, string returnUrl = null)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            returnUrl = returnUrl ?? Url.Content("~/");

            var userId = await _authenticatorService.GetAuthenticationUserId();

            if (String.IsNullOrEmpty(userId))
            {
                throw new InvalidOperationException($"Unable to load two-factor authentication user.");
            }

            var authenticatorCode = Input.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty);

            var result = await _authenticatorService.SignInAsync(authenticatorCode, rememberMe, Input.RememberMachine);

            if (result.Succeeded)
            {
                _logger.LogInformation("User with ID '{UserId}' logged in with 2fa.", userId);
                return(LocalRedirect(returnUrl));
            }
            else
            {
                _logger.LogWarning("Invalid authenticator code entered for user with ID '{UserId}'.", userId);
                ModelState.AddModelError(string.Empty, "Invalid authenticator code.");
                return(Page());
            }
        }