public async Task <ApiResponseDto> LoginWithRecoveryCode(LoginWithRecoveryCodeInputModel parameters) { ApiResponseDto apiResponse = await _accountApiClient.LoginWithRecoveryCode(parameters); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public async Task <ApiResponse> LoginWithRecoveryCode(LoginWithRecoveryCodeInputModel parameters) { try { // Ensure the user has gone through the username & password screen first var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); if (user == null) { return(new ApiResponse(Status404NotFound, "Unable to load two-factor authentication user.")); } var recoveryCode = parameters.RecoveryCode.Replace(" ", string.Empty); var context = await _interaction.GetAuthorizationContextAsync(parameters.ReturnUrl); var result = await _signInManager.TwoFactorRecoveryCodeSignInAsync(recoveryCode); // If lock out activated and the max. amounts of attempts is reached. if (result.IsLockedOut) { _logger.LogInformation("User Locked out: {0}", user.UserName); return(new ApiResponse(Status401Unauthorized, L["LockedUser"])); } // If your email is not confirmed but you require it in the settings for login. if (result.IsNotAllowed) { _logger.LogInformation("User {0} not allowed to log in, because email is not confirmed", user.UserName); return(new ApiResponse(Status401Unauthorized, L["EmailNotConfirmed"])); } if (result.Succeeded) { await _events.RaiseAsync(new UserLoginSuccessEvent(user.UserName, user.Id.ToString(), user.UserName, clientId : context?.Client?.ClientId)); _logger.LogInformation("User '{0}' logged in with a recovery code", user.UserName); return(new ApiResponse(Status200OK)); } await _events.RaiseAsync(new UserLoginFailureEvent(user.UserName, "Invalid recovery code for user {0}", clientId : context?.Client.ClientId)); _logger.LogInformation("Invalid recovery code for user {0}", user.UserName); return(new ApiResponse(Status401Unauthorized, L["LoginFailed"])); } catch (Exception ex) { _logger.LogError($"Login Failed: {ex.GetBaseException().Message}"); return(new ApiResponse(Status500InternalServerError, L["LoginFailed"])); } }
public async Task <ApiResponseDto> LoginWithRecoveryCode(LoginWithRecoveryCodeInputModel parameters) { var response = await _httpClient.PostJsonAsync <ApiResponseDto>("api/Account/LoginWithRecoveryCode", parameters); if (!_navigationManager.IsWebAssembly()) { if (response.IsSuccessStatusCode) { await SubmitServerForm("/server/loginwith2fa/", parameters); } } return(response); }
public async Task <ApiResponse> LoginWithRecoveryCode(LoginWithRecoveryCodeInputModel parameters) { return(ModelState.IsValid ? await _accountManager.LoginWithRecoveryCode(parameters) : _invalidData); }
public async Task <ApiResponseDto> LoginWithRecoveryCode(LoginWithRecoveryCodeInputModel parameters) { ApiResponseDto apiResponse = await _accountApiClient.LoginWithRecoveryCode(parameters); return(apiResponse); }