using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using CertAuth.Data; using CertAuth.Domain; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Authentication.OAuth; using Microsoft.AspNetCore.Http; using Microsoft.Identity.Web; using Microsoft.Identity.Web.UI; //using Microsoft.Identity.Web.TokenCacheProviders.InMemory; using Microsoft.IdentityModel.Logging; using Microsoft.Extensions.Options; namespace CertAuthAdmin { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Configuration to sign-in users with Azure AD B2C services.AddOptions(); services.Configure(Configuration.GetSection("AzureAdB2C")); services.AddSignIn(Configuration, "AzureAdB2C"); services.AddControllersWithViews() .AddMicrosoftIdentityUI(); services.AddRazorPages().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null); //services.AddControllers().AddControllersAsServices(); services.AddMvc(); #if DEBUG services.AddDbContext(opt => opt.UseSqlServer(Configuration.GetConnectionString("TESTQuartxDB")).EnableSensitiveDataLogging()); Globals.connStr = Configuration.GetConnectionString("TESTQuartxDB"); #else services.AddDbContext(opt => opt.UseSqlServer(Configuration.GetConnectionString("QuartxDB")).EnableSensitiveDataLogging()); Globals.connStr = Configuration.GetConnectionString("QuartxDB"); #endif // adding OIDC authentication //services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) // .AddSignIn("AzureAdB2C", Configuration, options => Configuration.Bind("AzureAdB2C", options)); //services.AddWebAppCallsProtectedWebApi(Configuration, // new string[] { "https;//certifiedauthentics.onmicrosoft.com/" }, configSectionName: "AzureAdB2C").AddInMemoryTokenCaches(); //services.Configure(Configuration.GetSection("AzureAdB2C")); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapRazorPages(); }); } } }