diff --git a/src/Skoruba.IdentityServer4.STS.Identity/Helpers/StartupHelpers.cs b/src/Skoruba.IdentityServer4.STS.Identity/Helpers/StartupHelpers.cs index aeb2a9d6e..27de18b02 100644 --- a/src/Skoruba.IdentityServer4.STS.Identity/Helpers/StartupHelpers.cs +++ b/src/Skoruba.IdentityServer4.STS.Identity/Helpers/StartupHelpers.cs @@ -96,16 +96,6 @@ public static IMvcBuilder AddMvcWithLocalization(this IServiceColle /// public static void UseSecurityHeaders(this IApplicationBuilder app, IConfiguration configuration) { - var forwardingOptions = new ForwardedHeadersOptions() - { - ForwardedHeaders = ForwardedHeaders.All - }; - - forwardingOptions.KnownNetworks.Clear(); - forwardingOptions.KnownProxies.Clear(); - - app.UseForwardedHeaders(forwardingOptions); - app.UseReferrerPolicy(options => options.NoReferrer()); // CSP Configuration to be able to use external resources diff --git a/src/Skoruba.IdentityServer4.STS.Identity/Startup.cs b/src/Skoruba.IdentityServer4.STS.Identity/Startup.cs index 38fb4ece0..7c989605b 100644 --- a/src/Skoruba.IdentityServer4.STS.Identity/Startup.cs +++ b/src/Skoruba.IdentityServer4.STS.Identity/Startup.cs @@ -13,6 +13,7 @@ using Skoruba.IdentityServer4.STS.Identity.Helpers; using System; using Skoruba.IdentityServer4.Shared.Configuration.Helpers; +using Microsoft.AspNetCore.HttpOverrides; namespace Skoruba.IdentityServer4.STS.Identity { @@ -40,6 +41,8 @@ public void ConfigureServices(IServiceCollection services) // Add email senders which is currently setup for SendGrid and SMTP services.AddEmailSenders(Configuration); + RegisterForwardedHeaders(services); + // Add services for authentication, including Identity model and external providers RegisterAuthentication(services); @@ -59,6 +62,7 @@ public void ConfigureServices(IServiceCollection services) public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { + app.UseForwardedHeaders(); app.UseCookiePolicy(); if (env.IsDevelopment()) @@ -109,6 +113,16 @@ public virtual void RegisterAuthorization(IServiceCollection services) services.AddAuthorizationPolicies(rootConfiguration); } + public virtual void RegisterForwardedHeaders(IServiceCollection services) + { + services.Configure(options => + { + options.ForwardedHeaders = ForwardedHeaders.All; + options.KnownNetworks.Clear(); + options.KnownProxies.Clear(); + }); + } + public virtual void UseAuthentication(IApplicationBuilder app) { app.UseIdentityServer();