// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { ThreadPool.SetMinThreads(200, 200); var appSettings = new FarmSettingsValues(); Configuration.GetSection("FarmSettings").Bind(appSettings); string json; using (var file = File.Open(appSettings.ConfigPath + Path.DirectorySeparatorChar + "HttpProxy.global.json", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var sr = new StreamReader(file, Encoding.UTF8, false)) { json = sr.ReadToEnd(); } } var global = JsonSerializer.Deserialize <GlobalConfig>(json, new JsonSerializerOptions() { PropertyNameCaseInsensitive = false, AllowTrailingCommas = false, ReadCommentHandling = JsonCommentHandling.Skip }); global.Init(); services.AddSingleton <IFarmSettings>(global); }
public void ConfigureServices(IServiceCollection services) { ThreadPool.SetMinThreads(200, 200); var appSettings = new FarmSettingsValues(); Configuration.GetSection("FarmSettings").Bind(appSettings); string json; using (var file = File.Open(appSettings.ConfigPath + Path.DirectorySeparatorChar + "KeyVault.json", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var sr = new StreamReader(file, Encoding.UTF8, false)) { json = sr.ReadToEnd(); } } var global = JsonSerializer.Deserialize <GlobalConfig>(json, new JsonSerializerOptions() { PropertyNameCaseInsensitive = false, AllowTrailingCommas = false, ReadCommentHandling = JsonCommentHandling.Skip }); global.Init(); services.AddSingleton <IFarmSettings>(global); var keyVault = new KeyVaultLogic(); keyVault.Initialize(global.KeyVault); services.AddSingleton <IKeyVaultLogic>(keyVault); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { LifetimeValidator = (before, expires, token, parameters) => expires > DateTime.UtcNow, ValidateAudience = false, ValidateIssuer = false, ValidateActor = false, ValidateLifetime = true, IssuerSigningKey = keyVault.GetSecurityKey() }; //options.Events = new JwtBearerEvents { // OnMessageReceived = context => { // var accessToken = context.Request.Query["access_token"]; // if (!string.IsNullOrEmpty(accessToken)) { // context.Token = context.Request.Query["access_token"]; // } // return Task.CompletedTask; // } //}; }) .AddNegotiate(); services.AddAuthorization((o) => { o.AddPolicy("Windows", p => { p.AddAuthenticationSchemes(NegotiateDefaults.AuthenticationScheme); p.RequireAuthenticatedUser(); }); }); services.AddControllers().AddJsonOptions(opts => { opts.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "KeyVault", Version = "v1" }); }); }