public async Task <ApiResponse> LoginWith2fa(LoginWith2faInputModel 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 authenticatorCode = parameters.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty); var context = await _interaction.GetAuthorizationContextAsync(parameters.ReturnUrl); var result = await _signInManager.TwoFactorAuthenticatorSignInAsync(authenticatorCode, parameters.RememberMe, parameters.RememberMachine); // 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 authenticator code", user.UserName); return(new ApiResponse(Status200OK)); } await _events.RaiseAsync(new UserLoginFailureEvent(user.UserName, "Invalid authenticator code for user {0}", clientId : context?.Client.ClientId)); _logger.LogInformation("Invalid authenticator 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> LoginWith2fa(LoginWith2faInputModel parameters) { var response = await _httpClient.PostJsonAsync <ApiResponseDto>("api/Account/LoginWith2fa", parameters); if (!_navigationManager.IsWebAssembly()) { if (response.IsSuccessStatusCode) { await SubmitServerForm("/server/loginwith2fa/", parameters); } } return(response); }
public async Task <ApiResponse> LoginWith2fa(LoginWith2faInputModel parameters) { return(ModelState.IsValid ? await _accountManager.LoginWith2fa(parameters) : _invalidData); }
public async Task <ApiResponseDto> LoginWith2fa(LoginWith2faInputModel parameters) { ApiResponseDto apiResponse = await _accountApiClient.LoginWith2fa(parameters); return(apiResponse); }