public static IServiceCollection AddChatbotSecretServiceCollection(this IServiceCollection services, string keyVaultAppId, string keyVaultCertThumbPrint, string keyVaultBaseUrl) { var secretService = new AzureKeyVaultService(keyVaultAppId, keyVaultCertThumbPrint, keyVaultBaseUrl); secretService.Initialize().Wait(); services.AddSingleton <ISecretService, AzureKeyVaultService>(provider => secretService); return(services); }
public void ConfigureServices(IServiceCollection services) { var configService = new ConfigService(); services.AddOptions(); services.AddMemoryCache(); services.AddChatbotConfigService(); var secretService = new AzureKeyVaultService( configService.Get <string>("KeyVaultAppId"), configService.Get <string>("KeyVaultCertThumbprint"), configService.Get <string>("KeyVaultBaseUrl")); secretService.Initialize().Wait(); services.AddSingleton <ISecretService, AzureKeyVaultService>(provider => secretService); services .AddDbContextFactory() .AddChatbotNLog() .AddTwitchServices() .AddApplicationServices() .AddSolr(secretService) .AddRabbitConnectionServices() .AddPrintfulClient(secretService) .AddFactories(); services.AddSignalR(); services.AddRouting(); services.AddAuthentication(op => { op.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; op.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme; op.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options => { }); services.AddOptions <JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme) .Configure <ISecretService>((options, secrets) => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secrets.GetSecret <string>("ApiSecretSymmetricKey"))), ValidateIssuer = true, ValidIssuer = secrets.GetSecret <string>("ApiValidIssuer"), ValidateAudience = true, ValidAudience = secrets.GetSecret <string>("ApiValidAudience") }; }); services.AddAuthorization(options => { options.AddPolicy(JwtBearerDefaults.AuthenticationScheme, builder => { builder.RequireAuthenticatedUser() .Build(); }); }); services.AddControllers().AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore); }