// 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, ZenithContext db, ApplicationDbContext context, RoleManager <IdentityRole> roleManager, UserManager <ApplicationUser> userManager) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); // Seed demo Activities and Events if they don't exist ZenithSeeder.Seed(db); // Create admin and member roles and accounts if they don't exist createRolesandUsers(context, roleManager, userManager); }
private List <Event> getEvents(ZenithContext db) { List <Event> events = new List <Event>(); events.Add(new Event() { EventId = 1, FromDate = new DateTime(2016, 10, 5, 19, 0, 0), ToDate = new DateTime(2016, 10, 5, 20, 0, 0), CreatedBy = "Amanda", IsActive = true, CreationDate = new DateTime(2016, 10, 4, 12, 0, 0), Activity = db.Activity.First(a => a.ActivityId == 1) }); events.Add(new Event() { EventId = 2, FromDate = new DateTime(2016, 10, 6, 10, 30, 0), ToDate = new DateTime(2016, 10, 6, 12, 0, 0), CreatedBy = "Bob", IsActive = false, CreationDate = new DateTime(2016, 10, 5, 12, 0, 0), Activity = db.Activity.First(a => a.ActivityId == 2) }); events.Add(new Event() { EventId = 3, FromDate = new DateTime(2016, 10, 7, 10, 30, 0), ToDate = new DateTime(2016, 10, 7, 12, 0, 0), CreatedBy = "Coot", IsActive = true, CreationDate = new DateTime(2016, 10, 6, 12, 0, 0), Activity = db.Activity.First(a => a.ActivityId == 3) }); return(events); }
public EventsApiController(ZenithContext context) { _context = context; }
public ActivitiesController(ZenithContext context) { _context = context; }
public HomeController(ZenithContext context) { db = context; }
// 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, ZenithContext context, ApplicationDbContext AppDbContext) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsProduction()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // global policy - assign here or on each controller app.UseCors("CorsPolicy"); // Register the validation middleware, that is used to decrypt // the access tokens and populate the HttpContext.User property. app.UseOAuthValidation(); // Register the OpenIddict middleware. app.UseOpenIddict(); app.UseMvcWithDefaultRoute(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); // for github deployment context.Database.Migrate(); SeedData.Initialize(context); }
// 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, ZenithContext db, ApplicationDbContext context, RoleManager <IdentityRole> roleManager, UserManager <ApplicationUser> userManager) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 //Use the new policy globally app.UseCors("AllowAll"); app.UseOAuthValidation(); app.UseOpenIddict(); //app.UseMvc(routes => //{ // routes.MapRoute( // name: "default", // template: "{controller=Home}/{action=Index}/{id?}"); //}); app.UseMvcWithDefaultRoute(); using (context = new ApplicationDbContext( app.ApplicationServices.GetRequiredService <DbContextOptions <ApplicationDbContext> >())) { context.Database.EnsureCreated(); if (!context.Applications.Any()) { context.Applications.Add(new OpenIddictApplication { // Assign a unique identifier to your client app: Id = "48BF1BC3-CE01-4787-BBF2-0426EAD21342", // Assign a display named used in the consent form page: DisplayName = "MVC Core client application", // Register the appropriate redirect_uri and post_logout_redirect_uri: RedirectUri = "http://localhost:53507/signin-oidc", LogoutRedirectUri = "http://localhost:53507/", ClientSecret = Crypto.HashPassword("secret_secret_secret"), // Note: use "public" for JS/mobile/desktop applications // and "confidential" for server-side applications. Type = OpenIddictConstants.ClientTypes.Confidential }); context.SaveChanges(); } } //TRYING WEB API AUTH // secretKey contains a secret passphrase only your server knows string secretKey = "mysupersecret_secretkey!123"; var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secretKey)); var tokenValidationParameters = new TokenValidationParameters { // The signing key must match! ValidateIssuerSigningKey = true, IssuerSigningKey = signingKey, // Validate the JWT Issuer (iss) claim ValidateIssuer = true, ValidIssuer = "ExampleIssuer", // Validate the JWT Audience (aud) claim ValidateAudience = true, ValidAudience = "ExampleAudience", // Validate the token expiry ValidateLifetime = true, // If you want to allow a certain amount of clock drift, set that here: ClockSkew = TimeSpan.Zero }; app.UseJwtBearerAuthentication(new JwtBearerOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, TokenValidationParameters = tokenValidationParameters }); //TOKEN // Add JWT generation endpoint: var options = new TokenProviderOptions { Audience = "ExampleAudience", Issuer = "ExampleIssuer", SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256), }; app.UseMiddleware <TokenProviderMiddleware>(Options.Create(options)); //END OF AUTH TRIAL // Seed demo Activities and Events if they don't exist ZenithSeeder.Seed(db); // Create admin and member roles and accounts if they don't exist createRolesandUsers(context, roleManager, userManager); }
// 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, ZenithContext context) { 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 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); context.Database.Migrate(); SeedData.Initialize(context); }