Beispiel #1
0
        protected async Task DisableAuthenticator()
        {
            try
            {
                var apiResponse = await identityAuthenticationStateProvider.DisableAuthenticator();

                if (apiResponse.IsSuccessStatusCode)
                {
                    viewNotifier.Show(L["Operation Successful"], ViewNotifierType.Success);
                    userViewModel = apiResponse.Result;
                    authenticatorVerificationCodeViewModel = new AuthenticatorVerificationCodeViewModel();
                    StateHasChanged();
                }
                else
                {
                    viewNotifier.Show(apiResponse.Message, ViewNotifierType.Error, L["Operation Failed"]);
                }
            }
            catch (Exception ex)
            {
                viewNotifier.Show(ex.Message, ViewNotifierType.Error, L["Operation Failed"]);
            }
        }
Beispiel #2
0
 public async Task <ApiResponseDto <UserViewModel> > EnableAuthenticator(AuthenticatorVerificationCodeViewModel parameters)
 {
     return(await _accountApiClient.EnableAuthenticator(parameters));
 }
Beispiel #3
0
        public async Task <ApiResponse> EnableAuthenticator(ClaimsPrincipal authenticatedUser, AuthenticatorVerificationCodeViewModel parameters)
        {
            var user = await _userManager.FindByIdAsync(authenticatedUser.GetSubjectId());

            if (user == null)
            {
                _logger.LogInformation(L["The user {0} doesn't exist", authenticatedUser.GetDisplayName()]);
                return(new ApiResponse(Status404NotFound, L["The user doesn't exist"]));
            }

            var verificationCode = parameters.Code.Replace(" ", string.Empty).Replace("-", string.Empty);

            var is2faTokenValid = await _userManager.VerifyTwoFactorTokenAsync(
                user, _userManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode);

            if (is2faTokenValid)
            {
                var result = await _userManager.SetTwoFactorEnabledAsync(user, true);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User '{0}' has enabled 2FA with an authenticator app.", user.UserName);

                    var userViewModel = await BuildUserViewModel(authenticatedUser);

                    if (await _userManager.CountRecoveryCodesAsync(user) == 0)
                    {
                        userViewModel.RecoveryCodes = (await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10)).ToArray();
                    }

                    return(new ApiResponse(Status200OK, L["Operation Successful"], userViewModel));
                }
                else
                {
                    return(new ApiResponse(Status400BadRequest, "Error while enabling 2FA"));
                }
            }
            else
            {
                _logger.LogWarning($"Verification code of {user.UserName} is invalid.");
                return(new ApiResponse(Status400BadRequest, L["VerificationCodeInvalid"]));
            }
        }
Beispiel #4
0
 public async Task <ApiResponseDto <UserViewModel> > EnableAuthenticator(AuthenticatorVerificationCodeViewModel parameters)
 {
     return(await _httpClient.PostJsonAsync <ApiResponseDto <UserViewModel> >("api/Account/EnableAuthenticator", parameters));
 }
 public async Task <ApiResponse> EnableAuthenticator(AuthenticatorVerificationCodeViewModel parameters)
 => ModelState.IsValid ? await _accountManager.EnableAuthenticator(User, parameters) : _invalidData;