public async Task <ActionResult> RegisterU2F(RegisterU2FViewModel model)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            if (!string.IsNullOrWhiteSpace(model.DeviceResponse))
            {
                try
                {
                    model.DeviceResponse = await u2FManagerService.FinishU2FRegistration(user.UserName, model.DeviceResponse, model.DeviceName, new StartedRegistration(model.Challenge, model.AppId))
                        ? "Registration was successful."
                        : "Registration failed.";

                    return(RedirectToAction("TwoFactorAuthentication"));
                }
                catch (Exception e)
                {
                    _logger.LogError(e.Message);
                }
            }

            ModelState.AddModelError("CustomError", "Bad device response");
            return(View(model));
        }
        public async Task <IActionResult> RegisterU2F()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var serverRegisterResponse = await u2FManagerService.StartU2FRegistration(user.UserName);

            var registerModel = new RegisterU2FViewModel
            {
                AppId     = serverRegisterResponse.AppId,
                Challenge = serverRegisterResponse.Challenge,
                Version   = serverRegisterResponse.Version
            };

            return(View("RegisterU2F", registerModel));
        }