using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; #if (OrganizationalAuth || IndividualB2CAuth) using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; #endif using Microsoft.AspNetCore.Builder; #if (IndividualLocalAuth) using Microsoft.AspNetCore.Identity; #endif using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; #if (IndividualLocalAuth) using Microsoft.EntityFrameworkCore; using Company.WebApplication1.Data; #endif using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; #if (OrganizationalAuth && OrgReadAccess) using Microsoft.IdentityModel.Protocols.OpenIdConnect; #endif #if (MultiOrgAuth) using Microsoft.IdentityModel.Tokens; #endif namespace Company.WebApplication1 { 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) { #if (IndividualLocalAuth) services.AddDbContext(options => #if (UseLocalDB) options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); #else options.UseSqlite( Configuration.GetConnectionString("DefaultConnection"))); #endif services.AddIdentity(options => options.Stores.MaxLengthForKeys = 128) .AddEntityFrameworkStores() .AddDefaultUI() .AddDefaultTokenProviders(); #elif (OrganizationalAuth || IndividualB2CAuth) services.AddAuthentication(sharedOptions => { sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; }) #if (OrganizationalAuth) .AddAzureAd(options => Configuration.Bind("AzureAd", options)) #elif (IndividualB2CAuth) .AddAzureAdB2C(options => Configuration.Bind("AzureAdB2C", options)) #endif .AddCookie(); #endif services.Configure(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { #if (UseBrowserLink) app.UseBrowserLink(); #endif app.UseDeveloperExceptionPage(); #if (IndividualLocalAuth) app.UseDatabaseErrorPage(); #endif } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); #if (OrganizationalAuth || IndividualAuth) app.UseAuthentication(); #endif app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } } }