public async Task <JsonResult> RegisterAuthenticatorKey()
        {
            AppUser user = await _userManager.GetUserAsync(User);

            string authenticatorKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(authenticatorKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                authenticatorKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }
            RegisterAuthenticatorKeyViewModel response = new RegisterAuthenticatorKeyViewModel
            {
                AuthenticatorKey = authenticatorKey
            };
            var validProviders = await _userManager.GetValidTwoFactorProvidersAsync(user);

            if (validProviders.Contains(_userManager.Options.Tokens.AuthenticatorTokenProvider))
            {
                user.IsAuthenticatorKeyEnabled = true;
                await _userManager.UpdateAsync(user);

                response.AlreadyActivated = true;
            }

            return(Json(response));
        }
        public async Task <JsonResult> RegisterAuthenticatorKey(RegisterAuthenticatorKeyViewModel model)
        {
            if (string.IsNullOrEmpty(model.Token))
            {
                return(Json(new { success = false, error = "Invalid token" }));
            }
            if (string.IsNullOrEmpty(model.AuthenticatorKey))
            {
                return(Json(new { success = false, error = "Invalid authenticator key" }));
            }
            AppUser user = await _userManager.GetUserAsync(User);

            if (await _userManager.VerifyTwoFactorTokenAsync(user, _userManager.Options.Tokens.AuthenticatorTokenProvider, model.Token))
            {
                user.IsAuthenticatorKeyEnabled = true;
                await _userManager.UpdateAsync(user);

                return(Json(new { success = true, error = string.Empty }));
            }
            return(Json(new { success = false, error = "Token was not verified successfully" }));
        }