Пример #1
0
        private async Task NextAsync()
        {
            try
            {
                await ButtonSpinner.SpinAsync(async() =>
                {
                    var user = await ApplicationUserService.GetUserByEmailAsync(UserEmailModel.Email);
                    if (user == null)
                    {
                        ValidationErrorMessage.DisplayError(nameof(UserEmailModel.Email), HESException.GetMessage(HESCode.UserNotFound));
                        return;
                    }

                    PasswordSignInModel.Email = UserEmailModel.Email;
                    HasSecurityKey            = (await Fido2Service.GetCredentialsByUserEmail(UserEmailModel.Email)).Count > 0;
                    AuthenticationStep        = AuthenticationStep.EnterPassword;
                });
            }
            catch (HESException ex)
            {
                ValidationErrorMessage.DisplayError(nameof(UserEmailModel.Email), ex.Message);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                SetErrorMessage(ex.Message);
            }
        }
Пример #2
0
        protected override async Task OnInitializedAsync()
        {
            try
            {
                ApplicationUserService = ScopedServices.GetRequiredService <IApplicationUserService>();
                Fido2Service           = ScopedServices.GetRequiredService <IFido2Service>();

                var code  = NavigationManager.GetQueryValue("code");
                var email = NavigationManager.GetQueryValue("email");

                // Check user exist
                User = await ApplicationUserService.GetUserByEmailAsync(email);

                if (User == null)
                {
                    RegistrationStep = SecurityKeyRegistrationStep.UserNotFound;
                }

                // Check key is already added
                var cred = await Fido2Service.GetCredentialsByUserEmail(User.Email);

                if (cred.Count > 0)
                {
                    RegistrationStep = SecurityKeyRegistrationStep.AlreadyAdded;
                }

                // Verify token
                var tokenIsValid = await ApplicationUserService.VerifyRegisterSecurityKeyTokenAsync(User, code);

                if (!tokenIsValid)
                {
                    RegistrationStep = SecurityKeyRegistrationStep.InvalidToken;
                }

                SetInitialized();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                SetLoadFailed(ex.Message);
            }
        }