Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #1028 - OpenIdConnectProtocolException - caused by Forwarded Headers #1029

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/Skoruba.IdentityServer4.STS.Identity/Helpers/StartupHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,6 @@ public static IMvcBuilder AddMvcWithLocalization<TUser, TKey>(this IServiceColle
/// <param name="configuration"></param>
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
Expand Down
14 changes: 14 additions & 0 deletions src/Skoruba.IdentityServer4.STS.Identity/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);

Expand All @@ -59,6 +62,7 @@ public void ConfigureServices(IServiceCollection services)

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseForwardedHeaders();
app.UseCookiePolicy();

if (env.IsDevelopment())
Expand Down Expand Up @@ -109,6 +113,16 @@ public virtual void RegisterAuthorization(IServiceCollection services)
services.AddAuthorizationPolicies(rootConfiguration);
}

public virtual void RegisterForwardedHeaders(IServiceCollection services)
{
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.All;
options.KnownNetworks.Clear();
options.KnownProxies.Clear();
});
}

public virtual void UseAuthentication(IApplicationBuilder app)
{
app.UseIdentityServer();
Expand Down