// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddAuthorization(o => { var authorizationPolicy = new AuthorizationPolicyBuilder(SchemeContants.DefaultSchema) .RequireAuthenticatedUser() .Build(); o.AddPolicy("RequireLoggedOnUsers", authorizationPolicy); }); services.Configure <ApiSettings>(Configuration.GetSection("Api")); services.Configure <WebSettings>(Configuration.GetSection("Web")); services.AddResponseCaching(); services.AddHealthChecks(); //services.Configure<ForwardedHeadersOptions>(options => //{ // options.KnownNetworks.Clear(); // options.KnownProxies.Clear(); // options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; //}); services.AddMvc(options => { options.CacheProfiles.Add("Default60", new CacheProfile() { Duration = 60 }); //Authorize Filter options.Filters.Add(new AuthorizeFilter("RequireLoggedOnUsers")); //Https Filter AddMvcOptions(options); }).AddJsonOptions( options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore ) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) .AddRazorPagesOptions(options => { options.AllowAreas = true; options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage"); options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout"); }); AddAuthentication(services); DependencyInjectorBootStrapper.RegisterServices(services, Environment, Configuration); }
// This method gets called by the runtime. Use this method to add services to the container public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.Configure <UtilOptions.AWSSettingOptions>(Configuration.GetSection("AWSSetting")); services.Configure <UtilOptions.SwaggerOptions>(Configuration.GetSection("Swagger")); var sp = services.BuildServiceProvider(); var swaggerOptions = sp.GetService <IOptions <UtilOptions.SwaggerOptions> >(); services.AddSwaggerGen(c => { c.SwaggerDoc(swaggerOptions.Value.Version, new Info { Version = swaggerOptions.Value.Version, Title = swaggerOptions.Value.Title, Description = swaggerOptions.Value.Description, TermsOfService = swaggerOptions.Value.TermsOfService, Contact = new Contact { Name = swaggerOptions.Value.ContactName, Email = swaggerOptions.Value.ContactEmail } }); var basePath = PlatformServices.Default.Application.ApplicationBasePath; var xmlPath = Path.Combine(basePath, "Service.xml"); if (File.Exists(xmlPath)) { c.IncludeXmlComments(xmlPath); } c.DescribeAllEnumsAsStrings(); }); DependencyInjectorBootStrapper.RegisterServices(services, Environment, Configuration); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddAuthorization(o => { var authorizationPolicy = new AuthorizationPolicyBuilder(PipelineSpaceSchemeContants.DefaultSchema) .RequireAuthenticatedUser() .Build(); o.AddPolicy("RequireLoggedOnUsers", authorizationPolicy); }); services.AddMvc().AddJsonOptions( options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore ); //services.AddSpaceLogging(Configuration); //Options services.Configure <Infra.Options.AuthenticationOptions>(Configuration.GetSection("Authentication")); services.Configure <ApplicationOptions>(Configuration.GetSection("Application")); services.Configure <VSTSServiceOptions>(Configuration.GetSection("VSTS")); services.Configure <FakeAccountServiceOptions>(Configuration.GetSection("FakeVSTS")); services.Configure <NotificationOptions>(Configuration.GetSection("Notification")); services.Configure <Infra.Options.SwaggerOptions>(Configuration.GetSection("Swagger")); var sp = services.BuildServiceProvider(); var authenticationOptions = sp.GetService <IOptions <Infra.Options.AuthenticationOptions> >(); var swaggerOptions = sp.GetService <IOptions <Infra.Options.SwaggerOptions> >(); services.AddSwaggerGen(c => { c.SwaggerDoc(swaggerOptions.Value.Version, new Info { Version = swaggerOptions.Value.Version, Title = swaggerOptions.Value.Title, Description = swaggerOptions.Value.Description, TermsOfService = swaggerOptions.Value.TermsOfService, Contact = new Contact { Name = swaggerOptions.Value.ContactName, Email = swaggerOptions.Value.ContactEmail } }); var basePath = PlatformServices.Default.Application.ApplicationBasePath; var xmlPath = Path.Combine(basePath, "Service.xml"); if (File.Exists(xmlPath)) { c.IncludeXmlComments(xmlPath); } c.DescribeAllEnumsAsStrings(); c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); }); services.AddCors(); services.AddAuthentication() .AddPolicyScheme(PipelineSpaceSchemeContants.DefaultSchema, PipelineSpaceSchemeContants.DefaultSchema, options => { options.ForwardDefaultSelector = c => { if (c.Request.Path.StartsWithSegments("/pipelineHub")) { return(JwtBearerDefaults.AuthenticationScheme); } if (c.Request.Path.StartsWithSegments("/internalapi")) { return(JwtBearerDefaults.AuthenticationScheme); } if (c.Request.Path.StartsWithSegments("/api-core")) { return(JwtBearerDefaults.AuthenticationScheme); } if (c.Request.Path.StartsWithSegments("/organizationprovidercredential/externallogins") || c.Request.Path.StartsWithSegments("/organizationprovidercredential/linklogin")) { return(JwtBearerDefaults.AuthenticationScheme); } return(PipelineSpaceSchemeContants.ApplicationSchema); }; }) .AddIdentityServerAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme, options => { options.Authority = authenticationOptions.Value.Authority; options.RequireHttpsMetadata = false; options.ApiName = authenticationOptions.Value.ApiName; options.NameClaimType = authenticationOptions.Value.NameClaimType; options.RoleClaimType = authenticationOptions.Value.RoleClaimType; options.TokenRetriever = PipelineSpaceTokenRetreiver.FromHeaderAndQueryString; }); DependencyInjectorBootStrapper.RegisterServices(services, Environment, Configuration); }