From edfc18d7f472c965db8c6e78bf8abf5f0646f924 Mon Sep 17 00:00:00 2001 From: littlefoot Date: Sun, 17 Jul 2022 20:55:28 -0400 Subject: [PATCH] Possible fix for incorrect auth redirect location --- WebNovelPortal/Controllers/AccountController.cs | 3 ++- WebNovelPortal/Program.cs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/WebNovelPortal/Controllers/AccountController.cs b/WebNovelPortal/Controllers/AccountController.cs index f22238e..766e807 100644 --- a/WebNovelPortal/Controllers/AccountController.cs +++ b/WebNovelPortal/Controllers/AccountController.cs @@ -19,7 +19,8 @@ namespace WebNovelPortal.Controllers { await HttpContext.ChallengeAsync(new AuthenticationProperties { - RedirectUri = redirect + RedirectUri = redirect, + }); } diff --git a/WebNovelPortal/Program.cs b/WebNovelPortal/Program.cs index 4c56134..5bf0ead 100644 --- a/WebNovelPortal/Program.cs +++ b/WebNovelPortal/Program.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.HttpOverrides; using Newtonsoft.Json; using Treestar.Shared.AccessLayers; using Treestar.Shared.Authentication.OIDC; @@ -19,6 +20,11 @@ builder.Services.AddControllers().AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); builder.Services.AddOIDCAuth(builder.Configuration); +builder.Services.Configure(options => +{ + options.ForwardedHeaders = + ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; +}); var app = builder.Build(); @@ -26,9 +32,15 @@ var app = builder.Build(); if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); + app.UseForwardedHeaders(); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } +else +{ + app.UseDeveloperExceptionPage(); + app.UseForwardedHeaders(); +} app.UseHttpsRedirection();