/// <summary> /// Instantiates a new NamedStaticApiKeyAttribute. /// </summary> /// <param name="options">The options.</param> /// <param name="key">The key.</param> public NamedStaticApiKeyAttributeImpl( IOptions <ApiKeyOptions> options, string key) { this.options = options.Value; this.key = key; }
public SearchService(IUnitOfWork unitOfWork, IMapper mapper, IOptions <ApiKeyOptions> options, ILogger <SearchService> logger) { _unitOfWork = unitOfWork; _searchResultRepository = _unitOfWork.GetRepository <SearchResult>(); _mapper = mapper; _apiKeyOptions = options.Value; _logger = logger; }
public async Task <ApiKey> CreateApiKeyAsync(ApiKeyOptions options, CancellationToken token = default) { var request = new RestRequest($"/api/client/account/api-keys", Method.POST) .AddJsonBody(options); var response = await HandleRequest <ApiKey>(request, token); return(response); }
public TMDbApi( ApiKeyOptions apiKeySettings, IDistributedCache cachingService, IMapper mapper, ILogger <TMDbApi> logger) : base(cachingService, logger) { _mapper = mapper; Client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKeySettings.TmdbKey}"); }
public void SetUp() { options = new ApiKeyOptions { YandexKey = "03.965152905:d22d4b2900f386d57c71e5cc744029e7", YandexUser = "******", GoogleKey = "AIzaSyB148E2gOgvQ-uDXrHPUdIncOY0mOQEJSs", GoogleCx = "004371770683300358078:ficqkfdm1xk" }; }
private List <ISearchSystem> GetSearchSystems(ApiKeyOptions apiKeyOptions) { ISearchSystemFactory searchSystemFactory = new SearchSystemFactory(); var searchSystems = new List <ISearchSystem> { searchSystemFactory.InitSearchSystemYandex(_logger, apiKeyOptions.YandexKey, apiKeyOptions.YandexUser), searchSystemFactory.InitSearchSystemGoogle(_logger, apiKeyOptions.GoogleKey, apiKeyOptions.GoogleCx), searchSystemFactory.InitSearchSystemBing(_logger, apiKeyOptions.BingKey) }; return(searchSystems); }
private HttpClient CreateClient(ApiKeyOptions options, HttpMessageOptions httpOptions) { var handler = new FakeHttpMessageHandler(httpOptions); var wrapper = new OptionsWrapper <ApiKeyOptions>(options); var authenticator = new ApiKeyHubSpotAuthenticator(wrapper) { InnerHandler = handler }; var client = new HttpClient(authenticator); return(client); }
private SemaphoreSlim _lock = new SemaphoreSlim(1); // All writes are sequential public ApiKeyProvider(string filePath, ApiKeyOptions options) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException(nameof(filePath)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } _filePath = filePath; _options = options; }
public static IServiceCollection AddApiKeyProvider(this IServiceCollection services, Action <ApiKeyOptions> o = null) { var env = services.BuildServiceProvider().GetRequiredService <IHostingEnvironment>(); var options = new ApiKeyOptions(); if (o != null) { o.Invoke(options); } services.AddSingleton <IApiKeyProvider>( new ApiKeyProvider(env.GetConfigPath("api-keys.json"), options)); return(services); }
public static IServiceCollection AddApiKeyProvider(this IServiceCollection services, Action <ApiKeyOptions> o = null) { string configRootPath = services.BuildServiceProvider().GetRequiredService <IHostingEnvironment>().ConfigRootPath(); var options = new ApiKeyOptions(); if (o != null) { o.Invoke(options); } services.AddSingleton <IApiKeyProvider>(service => { return(new ApiKeyProvider(Path.Combine(configRootPath, "api-keys.json"), options)); }); return(services); }
public static IServiceCollection AddBearerAuthentication(this IServiceCollection services, Action <ApiKeyOptions> configure = null) { var opts = new ApiKeyOptions(); if (configure != null) { configure.Invoke(opts); } IHostingEnvironment env = services.BuildServiceProvider().GetRequiredService <IHostingEnvironment>(); IConfiguration config = services.BuildServiceProvider().GetRequiredService <IConfiguration>(); var provider = new ApiKeyProvider(opts); provider.UseStorage(new ApiKeyFileStorage(env.GetConfigPath("api-keys.json"))); provider.UseStorage(new ApiKeyConfigStorage(config)); var validator = new BearerTokenValidator(provider); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = HttpSysDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options => { options.SecurityTokenValidators.Add(validator); options.Events = new JwtBearerEvents() { OnMessageReceived = ctx => { validator.OnReceivingToken(ctx); return(System.Threading.Tasks.Task.FromResult(0)); }, OnTokenValidated = ctx => { validator.OnValidatedToken(ctx); return(System.Threading.Tasks.Task.FromResult(0)); } }; }); return(services.AddSingleton <IApiKeyProvider>(provider)); }
public static IServiceCollection AddApiKeyProvider(this IServiceCollection services, Action <ApiKeyOptions> o = null) { var options = new ApiKeyOptions(); if (o != null) { o.Invoke(options); } IHostingEnvironment env = services.BuildServiceProvider().GetRequiredService <IHostingEnvironment>(); IConfiguration config = services.BuildServiceProvider().GetRequiredService <IConfiguration>(); var provider = new ApiKeyProvider(options); provider.UseStorage(new ApiKeyFileStorage(env.GetConfigPath("api-keys.json"))); provider.UseStorage(new ApiKeyConfigStorage(config)); return(services.AddSingleton <IApiKeyProvider>(provider)); }
public void ForLegacyUseKeyNameAsSchemeNameOnWWWAuthenticateHeader_default_false() { var options = new ApiKeyOptions(); Assert.False(options.ForLegacyUseKeyNameAsSchemeNameOnWWWAuthenticateHeader); }
public void ApiKeyProviderType_default_null() { var options = new ApiKeyOptions(); Assert.Null(options.ApiKeyProviderType); }
public void IgnoreAuthenticationIfAllowAnonymous_default_false() { var options = new ApiKeyOptions(); Assert.False(options.IgnoreAuthenticationIfAllowAnonymous); }
public void SuppressWWWAuthenticateHeader_default_false() { var options = new ApiKeyOptions(); Assert.False(options.SuppressWWWAuthenticateHeader); }
public void ForLegacyIgnoreExtraValidatedApiKeyCheck_default_false() { var options = new ApiKeyOptions(); Assert.False(options.ForLegacyIgnoreExtraValidatedApiKeyCheck); }
public async Task ApiKey_is_attached_to_request_in_querystring(string methodName, ApiKeyOptions options, Uri requestUri) { var method = new HttpMethod(methodName); var httpOptions = new HttpMessageOptions { HttpMethod = method, HttpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK) }; var client = CreateClient(options, httpOptions); using (var testRequest = new HttpRequestMessage(method, requestUri)) { var response = await client.SendAsync(testRequest); } Assert.That(httpOptions.HttpResponseMessage.RequestMessage.RequestUri.Query, Contains.Substring($"hapikey={options.ApiKey}")); }
public void UseApiKeyAuthentication_registers_needed_services(HubSpotClientConfigurator configurator, ApiKeyOptions apiKeyOptions, ServiceCollection services) { var configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddObject(apiKeyOptions); var configuration = configurationBuilder.Build(); configurator.UseApiKeyAuthentication(configuration); configurator.ApplyServiceConfigurations(services); var serviceProvider = services.BuildServiceProvider(); Assert.Multiple(() => { Assert.That(() => serviceProvider.GetRequiredService <IOptions <ApiKeyOptions> >(), Throws.Nothing); Assert.That(() => serviceProvider.GetRequiredService <ApiKeyHubSpotAuthenticator>(), Throws.Nothing); }); }
public ApiKeyProvider(ApiKeyOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); ResetCache(); }
public void Events_default_not_null() { var options = new ApiKeyOptions(); Assert.NotNull(options.Events); }