Beispiel #1
0
        /// <summary>
        /// Gets EAP-config file, either directly or after browser authentication.
        /// Prepares for redirect if no EAP-config.
        /// </summary>
        /// <returns>EapConfig object.</returns>
        /// <exception cref="EduroamAppUserException">description</exception>
        public async Task <EapConfig> DownloadEapConfig(IdentityProviderProfile profile)
        {
            if (string.IsNullOrEmpty(profile?.Id))
            {
                return(null);
            }

            // if OAuth
            if (profile.oauth || !string.IsNullOrEmpty(profile.redirect))
            {
                return(null);
            }

            try
            {
                return(await Task.Run(()
                                      => IdpDownloader.DownloadEapConfig(profile.Id)
                                      ));
            }
            catch (ApiUnreachableException e)
            {
                throw new EduroamAppUserException("HttpRequestException",
                                                  "Couldn't connect to the server.\n\n" +
                                                  "Make sure that you are connected to the internet, then try again.\n" +
                                                  "Exception: " + e.Message);
            }
            catch (ApiParsingException e)
            {
                throw new EduroamAppUserException("xml parse exception",
                                                  "The institution or profile is either not supported or malformed. " +
                                                  "Please select a different institution or profile.\n\n" +
                                                  "Exception: " + e.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// downloads eap config based on profileId
        /// seperated into its own function as this can happen either through
        /// user selecting a profile or a profile being autoselected
        /// </summary>
        /// <param name="profileId"></param>
        /// <param name="eapConfigXml"></param>
        /// <param name="skipOverview"></param>
        /// <returns>True if function navigated somewhere</returns>
        /// <exception cref="XmlException">Parsing eap-config failed</exception>
        private async Task <bool> HandleProfileSelect(string profileId, string eapConfigXml = null, bool skipOverview = false)
        {
            LoadPageLoading();
            IdentityProviderProfile profile = null;

            if (!string.IsNullOrEmpty(profileId) &&
                !string.IsNullOrEmpty(eapConfigXml))
            {
                // TODO: ^perhaps reuse logic from PersistingStore.IsReinstallable
                Debug.WriteLine(nameof(eapConfigXml) + " was set", category: nameof(HandleProfileSelect));

                eapConfig           = EapConfig.FromXmlData(eapConfigXml);
                eapConfig.ProfileId = profileId;
            }
            else
            {
                Debug.WriteLine(nameof(eapConfigXml) + " was not set", category: nameof(HandleProfileSelect));

                profile = IdpDownloader.GetProfileFromId(profileId);
                try
                {
                    eapConfig = await DownloadEapConfig(profile);
                }
                catch (EduroamAppUserException ex)                 // TODO: catch this on some higher level
                {
                    MessageBox.Show(
                        ex.UserFacingMessage,
                        caption: "geteduroam - Exception");
                    eapConfig = null;
                }
            }

            // reenable buttons after LoadPageLoading() disables them
            btnBack.IsEnabled = true;
            btnNext.IsEnabled = true;

            if (eapConfig != null)
            {
                if (!CheckIfEapConfigIsSupported(eapConfig))
                {
                    return(false);
                }

                if (HasInfo(eapConfig) && !skipOverview)
                {
                    LoadPageProfileOverview();
                    return(true);
                }
                if (ConnectToEduroam.EnumerateCAInstallers(eapConfig)
                    .Any(installer => installer.IsInstalledByUs || !installer.IsInstalled))
                {
                    LoadPageCertificateOverview();
                    return(true);
                }

                LoadPageLogin();
                return(true);
            }
            else if (!string.IsNullOrEmpty(profile?.redirect))
            {
                // TODO: add option to go to selectmethod from redirect
                LoadPageRedirect(new Uri(profile.redirect));
                return(true);
            }
            else if (profile?.oauth ?? false)
            {
                LoadPageOAuthWait(profile);
                return(true);
            }
            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Logic for navigating to forward
        /// </summary>
        /// <exception cref="XmlException">TODO catch</exception>
        public async void NextPage()
        {
            // adds current form to history for easy backtracking
            historyFormId.Add(currentFormId);
            switch (currentFormId)
            {
            case FormId.InstalledProfile:
                LoadPageMainMenu();
                break;

            case FormId.MainMenu:
                if (LocalEapConfig != null)
                {
                    eapConfig = LocalEapConfig;
                    LoadPageProfileOverview();
                    break;
                }
                if (pageMainMenu.UseExtracted)
                {
                    eapConfig = ExtractedEapConfig;
                    LoadPageProfileOverview();
                    break;
                }

                LoadPageSelectInstitution();
                break;

            case FormId.SelectInstitution:
                var profiles = IdpDownloader.GetIdentityProviderProfiles(pageSelectInstitution.IdProviderId);
                if (profiles.Count == 1)                         // skip the profile select and go with the first one
                {
                    string autoProfileId = profiles.FirstOrDefault().Id;
                    if (!string.IsNullOrEmpty(autoProfileId))
                    {
                        // if profile could not be handled then return to form
                        if (!await HandleProfileSelect(autoProfileId))
                        {
                            LoadPageSelectInstitution(refresh: false);
                        }
                        break;
                    }
                }
                LoadPageSelectProfile();
                break;

            case FormId.SelectProfile:
                string profileId = pageSelectProfile.ProfileId;
                // if profile could not be handled then return to form
                if (!await HandleProfileSelect(profileId))
                {
                    LoadPageSelectProfile(refresh: false);
                }
                break;

            case FormId.ProfileOverview:
                if (pageProfileOverview.ShowTou)
                {
                    LoadPageTermsOfUse();
                    break;
                }
                if (ConnectToEduroam.EnumerateCAInstallers(eapConfig)
                    .Any(installer => installer.IsInstalledByUs || !installer.IsInstalled))
                {
                    LoadPageCertificateOverview();
                    break;
                }

                LoadPageLogin();
                break;

            case FormId.TermsOfUse:
                historyFormId.Remove(currentFormId);
                PreviousPage();
                break;

            case FormId.CertificateOverview:
                LoadPageLogin();
                break;

            case FormId.Login:
                if (pageLogin.IsConnected)
                {
                    if (!App.Installer.IsRunningInInstallLocation)
                    {
                        Shutdown();
                    }
                    else
                    {
                        Hide();
                        LoadPageInstalledProfile();
                        historyFormId.Clear();
                    }
                    break;
                }
                pageLogin.ConnectClick();
                break;

            case FormId.Redirect:
                break;
            }


            // removes current form from history if it gets added twice
            if (historyFormId.LastOrDefault() == currentFormId)
            {
                historyFormId.RemoveAt(historyFormId.Count - 1);
            }

            UpdateBackButton();
        }