Exemple #1
0
        /// <summary>
        /// Creates a pop-up window
        /// </summary>
        /// <param name="sender">Profile select panel</param>
        /// <param name="e">Event parameters</param>
        public TwoFactorEnrollmentPopup(object sender, RequestTwoFactorEnrollmentEventArgs e)
        {
            var selection_panel = sender as ConnectingSelectPanel;

            User = e.User;
            AuthenticatingInstance = e.AuthenticatingInstance;
            Profile = e.Profile;

            // Prepare the list of methods.
            var last_method = Properties.Settings.Default.InstanceSettings.TryGetValue(AuthenticatingInstance.Base.AbsoluteUri, out var settings) ? settings.LastTwoFactorAuthenticationMethod : null;

            MethodList = new ObservableCollection <TwoFactorAuthenticationBasePanel>();
            TwoFactorAuthenticationBasePanel method;

            if (Profile.TwoFactorMethods.HasFlag(TwoFactorAuthenticationMethods.TOTP))
            {
                MethodList.Add(method = new TOTPEnrollmentPanel(selection_panel.Wizard, AuthenticatingInstance));
                if (last_method == method.ID)
                {
                    _selected_method = method;
                }
            }
            if (Profile.TwoFactorMethods.HasFlag(TwoFactorAuthenticationMethods.YubiKey))
            {
                MethodList.Add(method = new YubiKeyAuthenticationPanel(selection_panel.Wizard, AuthenticatingInstance));
                if (last_method == method.ID)
                {
                    _selected_method = method;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Pops-up 2-Factor Enrollment prompt.
        /// </summary>
        /// <param name="sender"><see cref="eduVPN.ViewModels.Panels.ConnectingSelectPanel"/> requiring enrollment</param>
        /// <param name="e">Event arguments. This method fills it with user input.</param>
        /// <remarks>Occurs when 2-Factor Authentication enrollment is requested.</remarks>
        private void ConnectWizard_RequestTwoFactorEnrollment(object sender, RequestTwoFactorEnrollmentEventArgs e)
        {
            var view_model = new ViewModels.Windows.TwoFactorEnrollmentPopup(sender, e);

            // Create a new 2FA enroll pop-up.
            var popup = new TwoFactorEnrollmentPopup()
            {
                Owner = this, DataContext = view_model
            };

            popup.Loaded += (object sender_popup, RoutedEventArgs e_popup) =>
            {
                // Set initial focus.
                if (view_model.SelectedMethod == null && view_model.MethodList.Count > 0)
                {
                    view_model.SelectedMethod = view_model.MethodList[0];
                    if (view_model.MethodList.Count > 1)
                    {
                        (popup.FindName("Method") as Control)?.Focus();
                    }
                }
            };

            // Set the event args to fill with data to be returned to the event sender.
            ((Button)popup.FindName("OK")).CommandParameter = e;

            // Run the 2FA enrollment pop-up and pass the credentials to be returned to the event sender.
            popup.ShowDialog();
        }