public void ConfigureServices(IServiceCollection services) { var marsRoverClientConfig = new HttpClientConfig(); Configuration.GetSection("MarsRover").Bind(marsRoverClientConfig); var marsRoverApiKeyConfig = new ApiKeyConfig(); Configuration.GetSection("Auth:MarsRover").Bind(marsRoverApiKeyConfig); services.AddSingleton <IApiKeyConfig>(marsRoverApiKeyConfig); services.AddHttpClient <IMarsRoverService, MarsRoverService>( client => { client.BaseAddress = marsRoverClientConfig.Url; client.DefaultRequestHeaders.Add("Accept", "application/json"); }); // TODO: Add retry services.AddHttpClient <IImageService, ImageService>(); services.AddScoped <IFileService, FileService>(); services.AddControllers(); }
private string GetApiKeyConfig(DeployArg arg) { arg.ApiKey = Guid.NewGuid().ToString("N"); var config = new ApiKeyConfig() { ChainKeys = new Dictionary <string, string> { { arg.SideChainId, arg.ApiKey } } }; var result = JsonSerializer.Instance.Serialize(config); return(result); }
private static IServiceCollection ConfigureServices() { var Configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile($"{AppDomain.CurrentDomain.BaseDirectory}\\appsettings.json", optional: false, reloadOnChange: true) .Build(); var services = new ServiceCollection(); var logger = new LoggerConfiguration() .ReadFrom.Configuration(Configuration) .Enrich.FromLogContext() .CreateLogger(); services.AddLogging(config => { config.AddSerilog(logger: logger, dispose: true); }); var appConfig = new AppConfig(); Configuration.GetSection("Input").Bind(appConfig); services.AddSingleton <IAppConfig>(appConfig); var marsRoverApiKeyConfig = new ApiKeyConfig(); Configuration.GetSection("Auth:MarsRover").Bind(marsRoverApiKeyConfig); services.AddSingleton <IApiKeyConfig>(marsRoverApiKeyConfig); var marsRoverClientConfig = new HttpClientConfig(); Configuration.GetSection("MarsRover").Bind(marsRoverClientConfig); services.AddHttpClient <IMarsRoverService, MarsRoverService>( client => { client.BaseAddress = marsRoverClientConfig.Url; client.DefaultRequestHeaders.Add("Accept", "application/json"); }); services.AddHttpClient <IImageService, ImageService>(); services.AddScoped <IFileService, FileService>(); services.AddTransient <ImageDownloadApp>(); return(services); }
private static async Task <dynamic> Login(ApiKeyConfig config, string userName, string userPassword, HttpClient client) { var content = new FormUrlEncodedContent(new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("client_id", config.ClientId), new KeyValuePair <string, string>("client_secret", config.ClientSecret), new KeyValuePair <string, string>("redirect_uri", @"http://*****:*****@"connect/token", content); var responseContent = await result.Content.ReadAsStringAsync(); var json = JsonConvert.DeserializeObject <dynamic>(responseContent); return(json); }
public ApiKeyMiddleware(RequestDelegate next, ApiKeyConfig apiKeyConfig) { _next = next; _apiKeyConfig = apiKeyConfig; }