// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app , IHostingEnvironment env , CampDbInitializer dbSeeder , CampIdentityInitializer identitySeeder , ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); // this is a global config, if we want to config separately we need to use polices app.UseCors(config => { //config.AllowAnyHeader() //.AllowAnyMethod() //.WithOrigins("http://linalekova.com"); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseAuthentication(); app.UseMvc(); dbSeeder.Seed().Wait(); identitySeeder.Seed().Wait(); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CampDbInitializer seeder, //LD STEP66 we add the parameter we want use in "Configure" method and the dependency injection layer will fulfill if possible CampIdentityInitializer identitySeeder //LD STEP28 ) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); //LD STEP14 //app.UseCors(cfg => //{ // cfg.AllowAnyHeader() // .AllowAnyMethod() // .WithOrigins("http://wildermuth.com"); //}); //LD STEP35 app.UseJwtBearerAuthentication(new JwtBearerOptions() { //LD we ask to the framework that if find the token then authenticate authomatically AutomaticAuthenticate = true, AutomaticChallenge = true, //LD following we have the parameter that we want Bearer will use to validate the token TokenValidationParameters = new TokenValidationParameters() { ValidIssuer = Configuration["Tokens:Issuer"], ValidAudience = Configuration["Tokens:Audience"], ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Tokens:Key"])), ValidateLifetime = true //LD verify that the token is not expired } }); //LD STEP19 app.UseIdentity(); //LD we want tha "Identity" is executed before MVC, we want protect before all the MVC process app.UseMvc(); //seeder.Seed().Wait(); //LD STEP77 here we just call it. //identitySeeder.Seed().Wait(); //LD STEP28 }
// 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, CampDbInitializer seeder, CampIdentityInitializer identitySeeder) { loggerFactory.AddConsole(_config.GetSection("Logging")); loggerFactory.AddDebug(); // Configuring Cors to be used globally. //app.UseCors(config => //{ // config.AllowAnyHeader() // .AllowAnyMethod() // .WithOrigins("http://www.google.com"); //}); app.UseIdentity(); app.UseJwtBearerAuthentication(new JwtBearerOptions() { AutomaticAuthenticate = true, AutomaticChallenge = true, TokenValidationParameters = new TokenValidationParameters() { ValidIssuer = _config["Tokens:Issuer"], ValidAudience = _config["Tokens:Audience"], ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Tokens:Key"])), ValidateLifetime = true } }); app.UseMvc(config => { //config.MapRoute("MainAPIRoute", "api/{controller}/{action}"); }); // If there's no data in our Db then the injected db initializer will seed the db. seeder.Seed().Wait(); identitySeeder.Seed().Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, CampDbInitializer seeder, ILoggerFactory loggerFactory, CampIdentityInitializer identitySeeder) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } loggerFactory.AddConsole(_config.GetSection("Logging")); loggerFactory.AddDebug(); //identity before mvc app.UseAuthentication(); app.UseMvc(); seeder.Seed().Wait(); //async identitySeeder.Seed().Wait(); }