Exemple #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);
            }
        }
 public OAuthWait(MainWindow mainWindow, IdentityProviderProfile profile)
 {
     this.mainWindow = mainWindow;
     this.profile    = profile;
     this.oauth      = new OAuth(new Uri(profile?.authorization_endpoint));
     // The url to send the user to
     authUri = oauth.CreateAuthUri();
     // The url to listen to for the user to be redirected back to
     prefix = oauth.GetRedirectUri();
     InitializeComponent();
     Load();
 }
Exemple #3
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);
        }