Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, DbSeeder dbSeeder, RedisMessagesHub messagesHub)
        {
            loggerFactory.AddProvider(new Log4NetProvider());


            // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
            using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
                .CreateScope())
            {
                serviceScope.ServiceProvider.GetService<ApplicationDbContext>().Database.Migrate();
            }

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());

            app.UseStaticFiles();

            app.UseIdentity();
            await dbSeeder.EnsureSeedData();
            app.UseFacebookAuthentication(options =>
            {
                options.AppId = Configuration["Authentication:Facebook:AppId"];
                options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
                options.Events = new OAuthEvents
                                     {
                                         OnRemoteError = ctx =>

                                         {
                                             ctx.Response.Redirect("/error?FailureMessage=" + UrlEncoder.Default.UrlEncode(ctx.Error.Message));
                                             ctx.HandleResponse();
                                             return Task.FromResult(0);
                                         }
                                     };
            });

            app.ConfigureForumsSockets(messagesHub, "/sockets");

            //app.UseOAuthAuthentication(new OAuthOptions
            //                               {
            //                                   AuthenticationScheme = "Google-AccessToken",
            //                                   DisplayName = "Google-AccessToken(oauth{1})",
            //                                   ClientId = Configuration["google:clientid"],
            //                                   ClientSecret = Configuration["google:clientsecret"],
            //                                   CallbackPath = new PathString("/signin-google-token"),
            //                                   AuthorizationEndpoint = GoogleDefaults.AuthorizationEndpoint,
            //                                   TokenEndpoint = GoogleDefaults.TokenEndpoint,
            //                                   Scope = {"openid", "profile", "email"},
            //                                   SaveTokensAsClaims = true
            //                               });

            //// See config.json
            //// https://console.developers.google.com/project
            //app.UseGoogleAuthentication(new GoogleOptions
            //                                {
            //                                    ClientId = Configuration["google:clientid"],
            //                                    ClientSecret = Configuration["google:clientsecret"],
            //                                    DisplayName = "Second google",
            //                                    Events = new OAuthEvents()
            //                                                 {
            //                                                     OnRemoteError = ctx =>

            //                                                     {
            //                                                         ctx.Response.Redirect("/error?FailureMessage=" + UrlEncoder.Default.UrlEncode(ctx.Error.Message));
            //                                                         ctx.HandleResponse();
            //                                                         return Task.FromResult(0);
            //                                                     }
            //                                                 }
            //                                });

            // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715

            //app.UseCompression();
            app.UseMvc(routes =>
            {
                routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
                //routes.MapRoute("DefaultApiPost", "Api/{controller}/{action}");
            });


        }