Example #1
0
        private void ApiKeyAuth(ClientFlurlHttpSettings settings)
        {
            async Task SetHeaders(HttpCall http)
            {
                var body      = http.RequestBody;
                var method    = http.Request.Method.Method.ToUpperInvariant();
                var url       = http.Request.RequestUri.PathAndQuery;
                var timestamp = await TimeHelper.GetCurrentTimestampAsync(this.Config.UseTimeApi)
                                .ConfigureAwait(false);

                var signature = ApiKeyAuthenticator.GenerateSignature(
                    timestamp,
                    method,
                    url,
                    body,
                    this.Config.Secret);

                http.FlurlRequest
                .WithHeader(HeaderNames.AccessKey, this.Config.ApiKey)
                .WithHeader(HeaderNames.AccessSign, signature)
                .WithHeader(HeaderNames.AccessTimestamp, timestamp)
                .WithHeader(HeaderNames.AccessPassphrase, this.Config.Passphrase);
            }

            settings.BeforeCallAsync = SetHeaders;
        }
Example #2
0
        private void ApiKeyAuth(ClientFlurlHttpSettings settings, CoinbaseClient client)
        {
            async Task SetHeaders(FlurlCall http)
            {
                var body   = http.RequestBody;
                var method = http.Request.Verb.Method.ToUpperInvariant();
                var url    = http.Request.Url.ToUri().PathAndQuery;

                string timestamp;

                if (this.UseTimeApi)
                {
                    var timeResult = await client.Data.GetCurrentTimeAsync().ConfigureAwait(false);

                    timestamp = timeResult.Data.Epoch.ToString();
                }
                else
                {
                    timestamp = TimeHelper.GetCurrentUnixTimestampSeconds().ToString(CultureInfo.CurrentCulture);
                }

                var signature = ApiKeyAuthenticator.GenerateSignature(timestamp, method, url, body, this.ApiSecret);

                http.Request
                .WithHeader(HeaderNames.AccessKey, this.ApiKey)
                .WithHeader(HeaderNames.AccessSign, signature)
                .WithHeader(HeaderNames.AccessTimestamp, timestamp);
            }

            settings.BeforeCallAsync = SetHeaders;
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FlurlClient"/> class.
 /// </summary>
 /// <param name="baseUrl">The base URL associated with this client.</param>
 public FlurlClient(string baseUrl = null)
 {
     BaseUrl             = baseUrl;
     Settings            = new ClientFlurlHttpSettings(FlurlHttp.GlobalSettings);
     _httpClient         = new Lazy <HttpClient>(() => Settings.HttpClientFactory.CreateHttpClient(HttpMessageHandler));
     _httpMessageHandler = new Lazy <HttpMessageHandler>(() => Settings.HttpClientFactory.CreateMessageHandler());
 }
Example #4
0
 public ClientConfigurator()
 {
     ClientSettings =
         new ClientFlurlHttpSettings(FlurlHttp.GlobalSettings)
     {
         HttpClientFactory = new HttpClientFactoryWithDecompressionEnabled()
     };
 }
Example #5
0
 public FakeFlurlClient(string baseUrl)
 {
     _baseUrl  = baseUrl;
     _headers  = new Dictionary <string, object>();
     _cookies  = new Dictionary <string, Cookie>();
     _settings = new ClientFlurlHttpSettings();
     _routes   = new List <RouteSetup>();
 }
Example #6
0
        private void UseOAuth(ClientFlurlHttpSettings settings, CoinbaseClient client)
        {
            async Task ApplyAuthorization(FlurlCall call)
            {
                call.Request.WithOAuthBearerToken(this.AccessToken);
            }

            settings.BeforeCallAsync = ApplyAuthorization;
        }
Example #7
0
        private void ApiKeyAuth(ClientFlurlHttpSettings settings)
        {
            async Task SetHeaders(FlurlCall call)
            {
                call.Request
                .WithHeader(PinataApiKey, this.Config.ApiKey)
                .WithHeader(PinataSecretApiKey, this.Config.ApiSecret);
            }

            settings.BeforeCallAsync = SetHeaders;
        }
Example #8
0
        protected FlurlBasedClient(Func <IClientConfigurator, IClientConfigurator> configurationBuilder)
        {
            if (configurationBuilder == null)
            {
                throw new ArgumentNullException(nameof(configurationBuilder));
            }

            var clientConfigurator = new ClientConfigurator();

            configurationBuilder(clientConfigurator);
            _baseUrl        = clientConfigurator.BaseUrl;
            _clientSettings = clientConfigurator.ClientSettings;

            _exceptionsTypesByStatusCodes =
                new Dictionary <HttpStatusCode, Type>
            {
                { HttpStatusCode.NotFound, typeof(NotFoundException) },
                { HttpStatusCode.Unauthorized, typeof(UnauthorizedException) },
                { HttpStatusCode.BadRequest, typeof(BadRequestException) }
            };
        }
Example #9
0
 /// <summary/>
 protected OpenStackNetConfigurationOptions()
 {
     _flurlHttpSettings      = new ClientFlurlHttpSettings();
     _jsonSerializerSettings = new JsonSerializerSettings();
     _userAgents             = new List <ProductInfoHeaderValue>();
 }