Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IAntiforgery antiforgery, IHostingEnvironment env,
            ILoggerFactory loggerFactory)
        {
            app.UseIdentity() 
                .UseDeveloperAuthAuthentication(
                    new DeveloperAuthOptions()
                    {
                        ConsumerKey = "uWkHwFNbklXgsLHYzLfRXcThw",
                        ConsumerSecret = "2kyg9WdUiJuU2HeWYJEuvwzaJWoweLadTgG3i0oHI5FeNjD5Iv"
                    })
                .UseTwitter2Authentication(
                    new Twitter2Options()
                    {
                        ConsumerKey = "uWkHwFNbklXgsLHYzLfRXcThw",
                        ConsumerSecret = "2kyg9WdUiJuU2HeWYJEuvwzaJWoweLadTgG3i0oHI5FeNjD5Iv"
                    });

            app.AddAllConfigureRegistrants();
            app.UseCookieAuthentication(options =>
            {
                options.LoginPath = new PathString("/Identity/Account/Login");
                options.LogoutPath = new PathString("/Identity/Account/LogOff");
            });

            /*
            app.UseProtectFolder(new ProtectFolderOptions
            {
                Path = "/Elm",
                PolicyName = "Authenticated"
            });
            */
            app.UseProtectLocalOnly(new ProtectLocalOnlyOptions());
            app.UseProtectPath(new ProtectPathOptions
            {
                PolicyName = "Authenticated"
            });

            app.UseElmPage(); // Shows the logs at the specified path
            app.UseElmCapture(); // Adds the ElmLoggerProvider

            loggerFactory.AddSerilog();
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                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())
                    {
#if ENTITY_IDENTITY
                        serviceScope.ServiceProvider.GetService<Pingo.Authorization.Models.ApplicationDbContext>()
                            .Database.Migrate();
#endif
                    }
                }
                catch
                {
                }
            }

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

            // due to an JWT defect we cannot be an IdentityServer4 and provide APIs 
            //app.UseIdentityServer();

            app.UseCors(policy =>
            {
                policy.WithOrigins(
                    "http://localhost:28895",
                    "http://localhost:14016",
                    "http://localhost:7017");

                policy.AllowAnyHeader();
                policy.AllowAnyMethod();
            });
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            app.UseIdentityServerAuthentication(options =>
            {
                options.Authority = WebApplication1.IdentityServerClients.Configuration.Constants.BaseAddress;
                options.ScopeName = "api1";
                options.ScopeSecret = "secret";

                options.AutomaticAuthenticate = true;
                options.AutomaticChallenge = true;
            });

            app.UseStaticFiles();


            // IMPORTANT: This session call MUST go before UseMvc()
            app.UseSession();

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

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "areaRoute",
                    template: "{area:exists}/{controller}/{action}",
                    defaults: new {action = "Index"});

                routes.MapRoute(
                    name: "default",
                    template: "{area=Main}/{controller=Home}/{action=Index}/{id?}");
            });

            app.UseSwaggerGen();
            app.UseSwaggerUi();
        }
Ejemplo n.º 2
0
        // 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,
                              IApplicationLifetime appLifetime)
        {
            app.UseMiddleware <Convert302ResponseMiddleware>();
            app.UseIpRateLimiting();

            //   LoadGraphQLAuthority();
            LoadIdentityServer4Data();

            var supportedCultures = new List <CultureInfo>
            {
                new CultureInfo("en-US"),
                new CultureInfo("en-AU"),
                new CultureInfo("en-GB"),
                new CultureInfo("es-ES"),
                new CultureInfo("ja-JP"),
                new CultureInfo("fr-FR"),
                new CultureInfo("zh"),
                new CultureInfo("zh-CN")
            };
            var options = new RequestLocalizationOptions
            {
                //     RequestCultureProviders = new List<IRequestCultureProvider>(),
                DefaultRequestCulture = new RequestCulture("en-US"),
                SupportedCultures     = supportedCultures,
                SupportedUICultures   = supportedCultures
            };

            app.UseRequestLocalization(options);

            ConfigureTagHelperBase(env);

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            // Add Serilog to the logging pipeline
            loggerFactory.AddSerilog();
            // Ensure any buffered events are sent at shutdown
            appLifetime.ApplicationStopped.Register(Log.CloseAndFlush);



            app.AddAllConfigureRegistrants();

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

            app.UseStaticFiles();
            var contentTypeProvider = new FileExtensionContentTypeProvider();

            contentTypeProvider.Mappings.Add(".tag", "text/plain");

            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider          = new CbvPhysicalFileProvider(env.WebRootPath),
                RequestPath           = new PathString("/cb-v"),
                ServeUnknownFileTypes = true,
                ContentTypeProvider   = contentTypeProvider
            });

            var root           = env.ContentRootFileProvider;
            var rewriteOptions = new MutableRewriteOptions()
                                 .AddIISUrlRewrite(root, "IISUrlRewrite.config");

            P7.Core.Global.ArbitraryObjects.Add("rewrite-optons", (object)rewriteOptions);
            app.UseP7Rewriter((RewriteOptions)P7.Core.Global.ArbitraryObjects["rewrite-optons"]);

            //enable session before MVC
            //=========================
            app.UseSession(new SessionOptions
            {
                CookieSecure = CookieSecurePolicy.SameAsRequest
            }
                           );

            app.UseAuthentication();
            app.UsePublicRefreshToken();
            app.UseIdentityServer();

            app.UseCors("CorsPolicy");

            app.UseMvc(routes =>
            {
                routes.MapRoute("areaRoute", "{area:exists}/{controller=Admin}/{action=Index}/{id?}");
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IAntiforgery antiforgery, IHostingEnvironment env,
                              ILoggerFactory loggerFactory)
        {
            app.UseIdentity()
            .UseDeveloperAuthAuthentication(
                new DeveloperAuthOptions()
            {
                ConsumerKey    = "uWkHwFNbklXgsLHYzLfRXcThw",
                ConsumerSecret = "2kyg9WdUiJuU2HeWYJEuvwzaJWoweLadTgG3i0oHI5FeNjD5Iv"
            })
            .UseTwitter2Authentication(
                new Twitter2Options()
            {
                ConsumerKey    = "uWkHwFNbklXgsLHYzLfRXcThw",
                ConsumerSecret = "2kyg9WdUiJuU2HeWYJEuvwzaJWoweLadTgG3i0oHI5FeNjD5Iv"
            });

            app.AddAllConfigureRegistrants();
            app.UseCookieAuthentication(options =>
            {
                options.LoginPath  = new PathString("/Identity/Account/Login");
                options.LogoutPath = new PathString("/Identity/Account/LogOff");
            });

            /*
             * app.UseProtectFolder(new ProtectFolderOptions
             * {
             *  Path = "/Elm",
             *  PolicyName = "Authenticated"
             * });
             */
            app.UseProtectLocalOnly(new ProtectLocalOnlyOptions());
            app.UseProtectPath(new ProtectPathOptions
            {
                PolicyName = "Authenticated"
            });

            app.UseElmPage();    // Shows the logs at the specified path
            app.UseElmCapture(); // Adds the ElmLoggerProvider

            loggerFactory.AddSerilog();
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                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())
                    {
#if ENTITY_IDENTITY
                        serviceScope.ServiceProvider.GetService <Pingo.Authorization.Models.ApplicationDbContext>()
                        .Database.Migrate();
#endif
                    }
                }
                catch
                {
                }
            }

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

            app.UseIdentityServer();

            app.UseCors(policy =>
            {
                policy.WithOrigins(
                    "http://localhost:28895",
                    "http://localhost:14016",
                    "http://localhost:7017");

                policy.AllowAnyHeader();
                policy.AllowAnyMethod();
            });

            app.UseStaticFiles();


            // IMPORTANT: This session call MUST go before UseMvc()
            app.UseSession();

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

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "areaRoute",
                    template: "{area:exists}/{controller}/{action}",
                    defaults: new { action = "Index" });

                routes.MapRoute(
                    name: "default",
                    template: "{area=Main}/{controller=Home}/{action=Index}/{id?}");
            });

            app.UseSwaggerGen();
            app.UseSwaggerUi();
        }
Ejemplo n.º 4
0
        // 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,
            IApplicationLifetime appLifetime)
        {
            LoadRazorProviderData();
            LoadIdentityServer4Data();
            LoadGraphQLAuthority();
            var dd = P7.Core.Global.ServiceProvider.GetServices <IQueryFieldRecordRegistration>();
            var vv = P7.Core.Global.ServiceProvider.GetService <IQueryFieldRecordRegistrationStore>();
            var v2 = P7.Core.Global.ServiceProvider.GetService <IPersistedGrantStore>();


            var supportedCultures = new List <CultureInfo>
            {
                new CultureInfo("en-US"),
                new CultureInfo("en-AU"),
                new CultureInfo("en-GB"),
                new CultureInfo("es-ES"),
                new CultureInfo("ja-JP"),
                new CultureInfo("fr-FR"),
                new CultureInfo("zh"),
                new CultureInfo("zh-CN")
            };
            var options = new RequestLocalizationOptions
            {
                //     RequestCultureProviders = new List<IRequestCultureProvider>(),
                DefaultRequestCulture = new RequestCulture("en-US"),
                SupportedCultures     = supportedCultures,
                SupportedUICultures   = supportedCultures
            };

            app.UseRequestLocalization(options);



            var version = typeof(Startup).GetTypeInfo()
                          .Assembly
                          .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                          .InformationalVersion;

            if (env.EnvironmentName == "Development")
            {
                version += "." + Guid.NewGuid().ToString().GetHashCode();
            }

            P7TagHelperBase.Version = version;
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            // Add Serilog to the logging pipeline
            loggerFactory.AddSerilog();
            // Ensure any buffered events are sent at shutdown
            appLifetime.ApplicationStopped.Register(Log.CloseAndFlush);

            app.UseIdentity()
            .UseDevAuthAuthentication(
                new DevAuthOptions()
            {
                ConsumerKey    = "uWkHwFNbklXgsLHYzLfRXcThw",
                ConsumerSecret = "2kyg9WdUiJuU2HeWYJEuvwzaJWoweLadTgG3i0oHI5FeNjD5Iv"
            })
            .UseTwitterAuthentication(
                new TwitterOptions()
            {
                ConsumerKey    = "uWkHwFNbklXgsLHYzLfRXcThw",
                ConsumerSecret = "2kyg9WdUiJuU2HeWYJEuvwzaJWoweLadTgG3i0oHI5FeNjD5Iv"
            });
            app.AddAllConfigureRegistrants();

            /*
             * CookieAuthenticationOptions cookieAuthenticationOptions = new CookieAuthenticationOptions
             * {
             *  AccessDeniedPath = new PathString("/Account/Forbidden/"),
             *  LoginPath = new PathString("/Identity/Account/Login"),
             *  LogoutPath = new PathString("/Identity/Account/LogOff"),
             *  AuthenticationScheme = "Cookies",
             *  AutomaticAuthenticate = true,
             *  AutomaticChallenge = false,
             *  Events = new CookieAuthenticationEvents()
             *  {
             *      OnRedirectToLogin = ctx =>
             *      {
             *          if (!ctx.Request.Path.StartsWithSegments("/api"))
             *          {
             *              ctx.Response.Redirect(ctx.RedirectUri);
             *          }
             *
             *          return Task.FromResult(0);
             *      }
             *  }
             * };
             * app.UseCookieAuthentication(cookieAuthenticationOptions);
             */
            app.UsePublicRefreshToken();
            app.UseIdentityServer();

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

            app.UseStaticFiles();
            var contentTypeProvider = new FileExtensionContentTypeProvider();

            contentTypeProvider.Mappings.Add(".tag", "text/plain");

            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider          = new CbvPhysicalFileProvider(env.WebRootPath),
                RequestPath           = new PathString("/cb-v"),
                ServeUnknownFileTypes = true,
                ContentTypeProvider   = contentTypeProvider
            });


            var root           = env.ContentRootFileProvider;
            var rewriteOptions = new MutableRewriteOptions()
                                 .AddIISUrlRewrite(root, "IISUrlRewrite.config");

            P7.Core.Global.ArbitraryObjects.Add("rewrite-optons", (object)rewriteOptions);
            app.UseP7Rewriter((RewriteOptions)P7.Core.Global.ArbitraryObjects["rewrite-optons"]);

            // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
            app.UseSession();

            // this gates any bearer token that comes in that does not have the 'abitrary'
            app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            {
                Authority            = "http://localhost:7791",
                RequireHttpsMetadata = false,
                EnableCaching        = false,
                AllowedScopes        = { "arbitrary" }
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute("areaRoute", "{area:exists}/{controller=Admin}/{action=Index}/{id?}");

                routes.MapRoute(
                    name: "default",
                    template: "{area=Main}/{controller=Home}/{action=Index}/{id?}");
            });
        }