Beispiel #1
0
        public GeocodingService(HttpClient client, IApiKey apiKey)
        {
            this.apiKey = apiKey;

            client.BaseAddress = new Uri("https://maps.googleapis.com/");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            Client = client;
        }
        public Task <IApiKey> ProvideAsync(string key)
        {
            IApiKey retKey = keyRepo.GetApiKey();

            return(retKey.Key.Equals(key)
                ? Task.FromResult(retKey)
                : Task.FromResult <IApiKey>(null));
        }
        void IApiKeyProvider.SetPublicApiKey(ApiKeyRole role, IApiKey apiKey)
        {
            var pair = _apiKeys.FirstOrDefault(k => k.Role == role);

            if (pair == null)
            {
                _apiKeys.Add(new Authenticator(role, null, apiKey));
            }
            else
            {
                pair.PublicKey = apiKey;
            }

            SaveApiKeys();
        }
        protected Tuple <string, string>[] PostParameters(IApiKey publicKey, IReadOnlyList <Tuple <string, string> > additionalParams = null)
        {
            var nonce = DateTime.Now.Ticks;

            var commonParamsCount     = 1;
            var additionalParamsCount = additionalParams == null ? 0 : additionalParams.Count;
            var parameters            = new Tuple <string, string> [commonParamsCount + additionalParamsCount];

            parameters[0] = Tuple.Create("nonce", nonce.ToString());

            if (additionalParams != null)
            {
                for (int i = 0, n = commonParamsCount; i < additionalParams.Count; i++, n++)
                {
                    parameters[n] = additionalParams[i];
                }
            }

            return(parameters);
        }
        private bool ApiKeyFromControls(object control, out IApiKey apiKey, out ApiKeyRole role)
        {
            apiKey = null;
            role   = ApiKeyRole.Account;

            var textBox = control as TextBox;

            if (textBox == null)
            {
                return(false);
            }

            var value = textBox.Text;

            if (!(textBox.Tag is ApiKeyRole))
            {
                throw new Exception("textBox.Tag is not ApiKeyRole");
            }

            apiKey = string.IsNullOrEmpty(value) ? null : new ApiKey(value);
            role   = (ApiKeyRole)textBox.Tag;
            return(true);
        }
Beispiel #6
0
        /// <summary>
        /// Creates a new <see cref="ISonarrClient"/> instance with the provided handler and details.
        /// </summary>
        /// <param name="handler">The <see cref="HttpClientHandler"/> used when constructing the internal HTTP client.</param>
        /// <param name="url">The URL of the Sonarr instance the <see cref="ISonarrClient"/> will target.</param>
        /// <param name="apiKey">The api key used in all RESTful requests for authentication.</param>
        /// <param name="allowRedirects">Instructs the <see cref="ISonarrClient"/> whether or not it should follow redirects.</param>
        /// <param name="proxyUrl">A proxy URL used by the <see cref="ISonarrClient"/> when sending requests.</param>
        /// <param name="proxyCredentials">A set of credentials to authenticate to the proxy.</param>
        /// <param name="bypassOnLocal">Indicates to bypass the proxy when a destination is determined to be local to the client.</param>
        /// <returns>An <see cref="ISonarrClient"/> instance with the specified settings.</returns>
        public static ISonarrClient GenerateClient(HttpClientHandler handler, ISonarrUrl url, IApiKey apiKey, bool allowRedirects,
                                                   string proxyUrl, ICredentials proxyCredentials, bool bypassOnLocal)
        {
            WebProxy proxy = null;

            if (!string.IsNullOrEmpty(proxyUrl))
            {
                proxy = new WebProxy(proxyUrl, bypassOnLocal);
                if (proxyCredentials != null)
                {
                    proxy.Credentials = proxyCredentials;
                }

                else
                {
                    proxy.UseDefaultCredentials = true;
                }
            }
            return(GenerateClient(handler, url, apiKey, allowRedirects, proxy));
        }
Beispiel #7
0
        internal static ISonarrClient GenerateClient(HttpClientHandler handler, ISonarrUrl url, IApiKey apiKey, bool allowRedirects, WebProxy proxy = null)
        {
            if (proxy != null)
            {
                handler.Proxy = proxy;
            }

            handler.AllowAutoRedirect = allowRedirects;
            var client = new SonarrRestClient(handler)
            {
                BaseAddress = url.Url
            };

            client.AddApiKey(apiKey);
            return(client);
        }
Beispiel #8
0
 public Authenticator(ApiKeyRole role, IApiKey privateKey, IApiKey publicKey)
 {
     Role       = role;
     PrivateKey = privateKey;
     PublicKey  = publicKey;
 }
Beispiel #9
0
 void IApiKeyProvider.SetPublicApiKey(ApiKeyRole role, IApiKey apiKey)
 {
     _apiKeyProvider.SetPublicApiKey(role, apiKey);
 }
Beispiel #10
0
 void IApiKeyProvider.SetPrivateApiKey(ApiKeyRole role, IApiKey apiKey)
 {
     _apiKeyProvider.SetPrivateApiKey(role, apiKey);
 }
Beispiel #11
0
        public Task <IApiKey> ProvideAsync(string key)
        {
            IApiKey apiKey = context.ApiKeys.FirstOrDefault(a => a.Key == key && a.Enabled);

            return(Task.FromResult(apiKey));
        }