// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SampleDataInitializer sampleData, UserManager<ApplicationUser> userManager) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859 try { using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>() .CreateScope()) { serviceScope.ServiceProvider.GetService<ApplicationDbContext>() .Database.Migrate(); } } catch { } } app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); app.UseStaticFiles(); app.UseIdentity(); // Refactor this into a seperate class // Remove hard coding of the password in the installDevices routine! app.UseBasicAuthentication(o => { o.Realm = $"j64 Alarm"; o.Events = new BasicAuthenticationEvents { OnSignIn = c => { var x = userManager.FindByNameAsync(c.UserName); x.Wait(); if (x.Result != null) { var y = userManager.CheckPasswordAsync(x.Result, c.Password); y.Wait(); if (y.Result == true) { var z = userManager.GetClaimsAsync(x.Result); z.Wait(); var identity = new ClaimsIdentity(z.Result, c.Options.AuthenticationScheme); c.Principal = new ClaimsPrincipal(identity); } } return Task.FromResult(true); } }; }); // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); // Seed some default entries into the database var task = sampleData.CreateMasterUser(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, UserManager<ApplicationUser> userManager, ApplicationDbContext ctx) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 // Refactor this into a seperate class // Remove hard coding of the password in the installDevices routine! app.UseBasicAuthentication(o => { o.Realm = $"j64 Alarm"; o.Events = new BasicAuthenticationEvents { OnSignIn = c => { var x = userManager.FindByNameAsync(c.UserName); x.Wait(); if (x.Result != null) { var y = userManager.CheckPasswordAsync(x.Result, c.Password); y.Wait(); if (y.Result == true) { var z = userManager.GetClaimsAsync(x.Result); z.Wait(); var identity = new ClaimsIdentity(z.Result, c.Options.AuthenticationScheme); c.Principal = new ClaimsPrincipal(identity); } } return Task.FromResult(true); } }; }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); // Seed some default entries into the database var task = new Data.UserDataInitializer(ctx, userManager).CreateMasterUser(); }