From 81c23200e4e0788a036167f3710bcc4323528c40 Mon Sep 17 00:00:00 2001 From: "MisterMik [MSFT]" <15340423+mistermik@users.noreply.github.com> Date: Thu, 25 Jan 2024 20:33:13 -0800 Subject: [PATCH] Update Program.cs App always redirect to localhost and not the current domain so, this does not work when using codespaces as the callback is a public domain. Fixing this problem by using UseForwardedHeaders, you ensure that your application correctly handles requests in scenarios where it is behind a proxy, which can affect URL generation and redirection. --- Quickstart/Sample/Program.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Quickstart/Sample/Program.cs b/Quickstart/Sample/Program.cs index 848f20b..719150c 100644 --- a/Quickstart/Sample/Program.cs +++ b/Quickstart/Sample/Program.cs @@ -1,4 +1,4 @@ -using Auth0.AspNetCore.Authentication; +using Auth0.AspNetCore.Authentication; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -8,6 +8,7 @@ using System.Net; using Microsoft.IdentityModel.Logging; +using Microsoft.AspNetCore.HttpOverrides; var builder = WebApplication.CreateBuilder(args); @@ -34,6 +35,14 @@ app.UseCookiePolicy(); app.UseRouting(); + + var fordwardedHeaderOptions = new ForwardedHeadersOptions + { + ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost + }; + fordwardedHeaderOptions.KnownNetworks.Clear(); + fordwardedHeaderOptions.KnownProxies.Clear(); +app.UseForwardedHeaders(fordwardedHeaderOptions); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => @@ -41,4 +50,4 @@ endpoints.MapDefaultControllerRoute(); }); -app.Run(); \ No newline at end of file +app.Run();