public override void PreInitialize() { #if !WITHOUTLDAP Configuration.Modules.ZeroLdap().Enable(typeof(LdapAuthenticationSource)); #endif Configuration.Auditing.IsEnabledForAnonymousUsers = false; //Declare entity types Configuration.Modules.Zero().EntityTypes.Tenant = typeof(Tenant); Configuration.Modules.Zero().EntityTypes.Role = typeof(Role); Configuration.Modules.Zero().EntityTypes.User = typeof(User); //Add/remove localization sources here Configuration.Localization.Sources.Add( new DictionaryBasedLocalizationSource( CoreConsts.LocalizationSourceName, new XmlEmbeddedFileLocalizationDictionaryProvider( Assembly.GetExecutingAssembly(), "Portal.Core.Localization.Source" ) ) ); RoleConfig.Configure(Configuration.Modules.Zero().RoleManagement); Configuration.Authorization.Providers.Add <AppAuthorizationProvider>(); Configuration.Settings.Providers.Add <AppSettingProvider>(); }
// 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, RoleManager <IdentityRole> roleManager) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddFile("logs/nakama-errors-{Date}.txt", LogLevel.Error); loggerFactory.AddFile("logs/nakama-{Date}.txt", LogLevel.Warning); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); loggerFactory.AddDebug(); } else { app.UseStatusCodePages(); } app.UseRewriter(new RewriteOptions() .AddRedirectToHttpsPermanent() .Add(new RedirectWwwRule())); app.UseResponseCompression(); app.UseStaticFiles(); app.UseIdentity(); var jwtAppSettingOptions = Configuration.GetSection(nameof(JwtIssuerOptions)); var tokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = jwtAppSettingOptions[nameof(JwtIssuerOptions.Issuer)], ValidateAudience = true, ValidAudience = jwtAppSettingOptions[nameof(JwtIssuerOptions.Audience)], ValidateIssuerSigningKey = true, IssuerSigningKey = SigningKey, RequireExpirationTime = true, ValidateLifetime = true, ClockSkew = TimeSpan.Zero }; app.UseJwtBearerAuthentication(new JwtBearerOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, TokenValidationParameters = tokenValidationParameters }); app.UseGoogleAuthentication(new GoogleOptions { ClientId = Configuration["Authentication:Google:ClientId"], ClientSecret = Configuration["Authentication:Google:ClientSecret"] }); app.UseFacebookAuthentication(new FacebookOptions { ClientId = Configuration["Authentication:Facebook:ClientId"], ClientSecret = Configuration["Authentication:Facebook:ClientSecret"] }); app.UseTwitterAuthentication(new TwitterOptions { ConsumerKey = Configuration["Authentication:Twitter:ConsumerKey"], ConsumerSecret = Configuration["Authentication:Twitter:ConsumerSecret"], RetrieveUserDetails = true }); app.UseRedditAuthentication(new RedditAuthenticationOptions { ClientId = Configuration["Authentication:Reddit:ClientId"], ClientSecret = Configuration["Authentication:Reddit:ClientSecret"] }); app.UseTwitchAuthentication(new TwitchAuthenticationOptions { ClientId = Configuration["Authentication:Twitch:ClientId"], ClientSecret = Configuration["Authentication:Twitch:ClientSecret"] }); app.UseDiscordAuthentication(new DiscordAuthenticationOptions { ClientId = Configuration["Authentication:Discord:ClientId"], ClientSecret = Configuration["Authentication:Discord:ClientSecret"], Scope = { "identify", "email" } }); RoleConfig.Configure(roleManager); app.Use(async(context, next) => { await next(); if (context.Response.StatusCode == 404 && !context.Request.Path.Value.StartsWith("/api")) { context.Items[MetaResultModel.StateKey] = context.Request.Path.Value; context.Request.Path = "/"; context.Response.StatusCode = 200; await next(); } }); app.UseMvc(routes => { routes.MapRoute( "default", "{controller=Home}/{action=Index}/{id?}"); }); }