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; }
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; }
/// <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()); }
public ClientConfigurator() { ClientSettings = new ClientFlurlHttpSettings(FlurlHttp.GlobalSettings) { HttpClientFactory = new HttpClientFactoryWithDecompressionEnabled() }; }
public FakeFlurlClient(string baseUrl) { _baseUrl = baseUrl; _headers = new Dictionary <string, object>(); _cookies = new Dictionary <string, Cookie>(); _settings = new ClientFlurlHttpSettings(); _routes = new List <RouteSetup>(); }
private void UseOAuth(ClientFlurlHttpSettings settings, CoinbaseClient client) { async Task ApplyAuthorization(FlurlCall call) { call.Request.WithOAuthBearerToken(this.AccessToken); } settings.BeforeCallAsync = ApplyAuthorization; }
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; }
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) } }; }
/// <summary/> protected OpenStackNetConfigurationOptions() { _flurlHttpSettings = new ClientFlurlHttpSettings(); _jsonSerializerSettings = new JsonSerializerSettings(); _userAgents = new List <ProductInfoHeaderValue>(); }