Example #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IEnsureSeedData seeder, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseAuthentication();

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            seeder.Seed(serviceProvider).Wait();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
Example #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, IEnsureSeedData seeder, IServiceProvider serviceProvider)
        {
            // Resolve dependency
            var appSetting              = serviceProvider.GetService <IOptions <AppSettingUtil> >().Value;
            var defaultApiResource      = serviceProvider.GetService <IDefaultApiResources>();
            var defaultIdentityResource = serviceProvider.GetService <IDefaultIdentityResources>();
            var stringConstant          = serviceProvider.GetService <IStringConstant>();

            // Initializing default APIResource and IdentityResources
            IdentityServerInitialize databaseInitialize = new IdentityServerInitialize();

            databaseInitialize.InitializeDatabaseForPreDefinedAPIResourceAndIdentityResources(app, defaultApiResource, defaultIdentityResource);

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

            //add NLog to ASP.NET Core
            loggerFactory.AddNLog();
            //needed for non-NETSTANDARD platforms: configure nlog.config in your project root
            loggerFactory.ConfigureNLog("nlog.config");

            LayoutRenderer.Register("basedir", (logEvent) => env.ContentRootPath);
            //Call the Seed method in (Seed.EnsureSeedData) to create initial Admin
            seeder.Seed(serviceProvider);

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

            app.UseStaticFiles();

            app.UseMiddleware <OAuthMiddleware>();

            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            app.UseIdentity();
            app.UseIdentityServer();

            // Allowing authentication for API resource of read-only with limit scope
            app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            {
                Authority            = appSetting.PromactOAuthUrl ?? "https://oauth.promactinfo.com",
                RequireHttpsMetadata = false,
                ApiName       = stringConstant.APIResourceName,
                AllowedScopes = new List <string>()
                {
                    IdentityServerConstants.StandardScopes.Email,
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    stringConstant.APIResourceUserReadScope,
                    stringConstant.APIResourceProjectReadScope
                },
                ApiSecret = appSetting.AuthenticationAPISecret,
            });

            //If staging or production then only use exceptionless
            if (env.IsProduction())
            {
                app.UseExceptionless(Configuration["ExceptionLess:ExceptionLessApiKey"]);
            }

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "Login",
                    template: "Login",
                    defaults: new { controller = "Account", action = "Login" });

                routes.MapRoute(
                    name: "LogOff",
                    template: "LogOff",
                    defaults: new { controller = "Account", action = "LogOff" });

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