var builder = WebApplication.CreateBuilder(args); builder.AddServiceDefaults(); builder.Services.AddControllersWithViews(); builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("IdentityDb"))); builder.Services.AddIdentity() .AddEntityFrameworkStores() .AddDefaultTokenProviders(); builder.Services.AddIdentityServer(options => { options.IssuerUri = "null"; options.Authentication.CookieLifetime = TimeSpan.FromHours(2); options.Events.RaiseErrorEvents = true; options.Events.RaiseInformationEvents = true; options.Events.RaiseFailureEvents = true; options.Events.RaiseSuccessEvents = true; }) .AddInMemoryIdentityResources(Config.GetResources()) .AddInMemoryApiScopes(Config.GetApiScopes()) .AddInMemoryApiResources(Config.GetApis()) .AddInMemoryClients(Config.GetClients(builder.Configuration)) .AddAspNetIdentity() .AddDeveloperSigningCredential(); // Not recommended for production - you need to store your key material somewhere secure builder.Services.AddHealthChecks() .AddSqlServer(_ => builder.Configuration.GetRequiredConnectionString("IdentityDb"), name: "IdentityDB-check", tags: new string[] { "IdentityDB" }); builder.Services.AddTransient(); builder.Services.AddTransient, EFLoginService>(); builder.Services.AddTransient(); var app = builder.Build(); app.UseServiceDefaults(); app.UseStaticFiles(); // This cookie policy fixes login issues with Chrome 80+ using HHTP app.UseCookiePolicy(new CookiePolicyOptions { MinimumSameSitePolicy = SameSiteMode.Lax }); app.UseRouting(); app.UseIdentityServer(); app.UseAuthorization(); app.MapDefaultControllerRoute(); // Apply database migration automatically. Note that this approach is not // recommended for production scenarios. Consider generating SQL scripts from // migrations instead. using (var scope = app.Services.CreateScope()) { await SeedData.EnsureSeedData(scope, app.Configuration, app.Logger); } await app.RunAsync();