示例#1
0
 public TimeTaskExecutor(Uri endpointUri, ICallData callData, ILogger logger, ApiKeysStrings apiKeys)
 {
     _endpointUri  = endpointUri;
     _callData     = callData;
     _logger       = logger;
     _clientPolicy = Policy.Handle <HttpRequestException>()
                     .WaitAndRetryAsync(new[] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2) },
                                        (exception, span) =>
     {
         _logger.LogDebug($"Retrying after exception: {exception} {exception.Message}");
     });
     _httpClient.DefaultRequestHeaders.Add("X-API-Key", apiKeys.ClientKey);
 }
示例#2
0
        protected virtual void ConfigureApiKeyAuthentication(IServiceCollection services)
        {
            var apiKeys = new ApiKeysStrings();

            apiKeys.ClientKey       = Environment.GetEnvironmentVariable(nameof(apiKeys.ClientKey));
            apiKeys.ManagmentAppKey = Environment.GetEnvironmentVariable(nameof(apiKeys.ManagmentAppKey));
            services.AddSingleton(apiKeys);
            services.AddSingleton <ApiKeyService>();
            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = ApiKeyAuthenticationOptions.Scheme;
                options.DefaultChallengeScheme    = ApiKeyAuthenticationOptions.Scheme;
            })
            .AddScheme <ApiKeyAuthenticationOptions, ApiKeyAuthenticationHandler>(ApiKeyAuthenticationOptions.Scheme,
                                                                                  null);
        }
示例#3
0
 public EchoJob(ILogger <EchoJob> logger, ApiKeysStrings apiKeys)
 {
     _logger  = logger;
     _apiKeys = apiKeys;
 }