private HttpWebRequest CreateRequest(string url, string method = "GET", string contenttype = "text/xml")
        {
            var request = (HttpWebRequest)WebRequest.Create(url);

            request.Method            = method;
            request.ContentType       = contenttype;
            request.Credentials       = _creds;
            request.PreAuthenticate   = true;
            request.AllowAutoRedirect = true;

            if (_proxyProvider != null)
            {
                request.Proxy = _proxyProvider.CreateWebProxy();
            }

            request.Headers.Add("Accept-Language", CultureInfo.CurrentCulture.Name);
            request.UserAgent = MyUserAgent;
            foreach (var pair in _customHttpHeaders)
            {
                request.Headers.Add(pair.Key, pair.Value);
            }

            request.CookieContainer = CookieContainer;
            request.UnsafeAuthenticatedConnectionSharing = true;
            return(request);
        }
 public V1CredsAPIConnector(string urlPrefix, System.Net.ICredentials creds = null, ProxyProvider proxy = null)
 {
     _urlPrefix     = urlPrefix;
     _proxyProvider = proxy;
     _creds         = creds ?? CredentialCache.DefaultCredentials;
     var myproxy = _proxyProvider == null ? null : _proxyProvider.CreateWebProxy();
 }
		public V1CredsAPIConnector(string urlPrefix, System.Net.ICredentials creds = null, ProxyProvider proxy = null)
		{
			_urlPrefix = urlPrefix;
			_proxyProvider = proxy;
			_creds = creds ?? CredentialCache.DefaultCredentials;
			var myproxy = _proxyProvider == null ? null : _proxyProvider.CreateWebProxy();
		}
		public V1APIConnector(string urlPrefix, string username = null, string password = null, bool? integratedAuth = null,
							  ProxyProvider proxy = null, OAuth2Client.IStorage storage = null)
			: base(urlPrefix, new CredentialCache(), proxy)
		{
			var cache = _creds as CredentialCache;
			var uri = new Uri(urlPrefix);

			// Try the OAuth2 credential
			OAuth2Client.IStorage oauth2storage = null;
			if (storage != null)
			{
				oauth2storage = storage;
			}
			else
			{
				try
				{
					var s = OAuth2Client.Storage.JsonFileStorage.Default as OAuth2Client.IStorage;
					s.GetSecrets();
					oauth2storage = s;
				}
				catch (System.IO.FileNotFoundException)
				{
					// swallowed - meaning no oauth2 secrets configured.
				}
			}
			if (oauth2storage != null)
			{
				cache.Add(uri,
					"Bearer",
					new OAuth2Client.OAuth2Credential(
						"apiv1",
						oauth2storage,
						proxy != null ? proxy.CreateWebProxy() : null
						)
					);
			}

			if (username == null)
			{
				if (integratedAuth.GetValueOrDefault(true))
				{ // no constructor args - so use default integrated identity unless they say no.
					cache.Add(uri, "NTLM", CredentialCache.DefaultNetworkCredentials);
					cache.Add(uri, "Negotiate", CredentialCache.DefaultNetworkCredentials);
				}
			}
			else
			{
				var userPassCred = new NetworkCredential(username, password);
				cache.Add(uri, "Basic", userPassCred);

				if (!integratedAuth.GetValueOrDefault(false))
				{ // If there's a username, we'll assume the user doesn't want Windows Auth unless they ask.
					cache.Add(uri, "NTLM", userPassCred);
					cache.Add(uri, "Negotiate", userPassCred);
				}
			}
		}
Beispiel #5
0
        public V1APIConnector(string urlPrefix, string username = null, string password = null, bool?integratedAuth = null,
                              ProxyProvider proxy = null, OAuth2Client.IStorage storage = null)
            : base(urlPrefix, new CredentialCache(), proxy)
        {
            var cache = _creds as CredentialCache;
            var uri   = new Uri(urlPrefix);

            // Try the OAuth2 credential
            OAuth2Client.IStorage oauth2storage = null;
            if (storage != null)
            {
                oauth2storage = storage;
            }
            else
            {
                try
                {
                    var s = OAuth2Client.Storage.JsonFileStorage.Default as OAuth2Client.IStorage;
                    s.GetSecrets();
                    oauth2storage = s;
                }
                catch (System.IO.FileNotFoundException)
                {
                    // swallowed - meaning no oauth2 secrets configured.
                }
            }
            if (oauth2storage != null)
            {
                cache.Add(uri,
                          "Bearer",
                          new OAuth2Client.OAuth2Credential(
                              "apiv1",
                              oauth2storage,
                              proxy != null ? proxy.CreateWebProxy() : null
                              )
                          );
            }

            if (username == null)
            {
                if (integratedAuth.GetValueOrDefault(true))
                {                 // no constructor args - so use default integrated identity unless they say no.
                    cache.Add(uri, "NTLM", CredentialCache.DefaultNetworkCredentials);
                    cache.Add(uri, "Negotiate", CredentialCache.DefaultNetworkCredentials);
                }
            }
            else
            {
                var userPassCred = new NetworkCredential(username, password);
                cache.Add(uri, "Basic", userPassCred);

                if (!integratedAuth.GetValueOrDefault(false))
                {                 // If there's a username, we'll assume the user doesn't want Windows Auth unless they ask.
                    cache.Add(uri, "NTLM", userPassCred);
                    cache.Add(uri, "Negotiate", userPassCred);
                }
            }
        }
            ICanGetConnector ICanSetProxyOrGetConnector.WithProxy(ProxyProvider proxyProvider)
            {
                if (proxyProvider == null)
                {
                    throw new ArgumentNullException("proxyProvider");
                }

                _instance._webProxy = proxyProvider.CreateWebProxy();

                return(this);
            }
        private HttpWebRequest CreateRequest(string path)
        {
            var request = (HttpWebRequest)WebRequest.Create(path);

            AddBearer(request);
            if (proxyProvider != null)
            {
                request.Proxy = proxyProvider.CreateWebProxy();
            }

            request.Headers.Add("Accept-Language", CultureInfo.CurrentCulture.Name);

            foreach (var pair in customHttpHeaders)
            {
                request.Headers.Add(pair.Key, pair.Value);
            }

            request.CookieContainer = CookieContainer;
            request.UnsafeAuthenticatedConnectionSharing = true;
            return(request);
        }