Add PublicUrl support for reverse proxy handling
Build and Push Docker Image / build-and-push (push) Successful in 19s

Introduced a `PUBLIC_URL` environment variable to configure the
public URL for OAuth callbacks and reverse proxy scenarios. Updated
`Program.cs` to rewrite request scheme and host based on `PublicUrl`.
Replaced `Microsoft.AspNetCore.Components.Authorization` with
`Microsoft.AspNetCore.Components.Authentication`. Added `PublicUrl`
to `appsettings.json` with a default empty value.
This commit is contained in:
Arne Moerman
2026-05-17 22:06:16 +02:00
parent 2bf0295508
commit dbaf1bc361
4 changed files with 22 additions and 5 deletions
+3
View File
@@ -1,6 +1,9 @@
# Required for SQL Server container and app DB connection
SA_PASSWORD=ChangeThisToAStrongPassword123!
# Public URL of the site (used to fix OAuth callbacks behind a reverse proxy)
PUBLIC_URL=https://yourdomain.example.com
# Optional OAuth (leave empty to disable provider at runtime)
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
+1
View File
@@ -22,6 +22,7 @@ services:
- Smtp__Password=${SMTP_PASSWORD}
- Smtp__FromAddress=${SMTP_FROM_ADDRESS}
- Smtp__FromName=${SMTP_FROM_NAME}
- PublicUrl=${PUBLIC_URL}
depends_on:
- mssql
networks:
+16 -4
View File
@@ -1,6 +1,10 @@
using System.Data;
using BirthList.Infrastructure.Persistence;
using BirthList.Web.Authorization;
using BirthList.Web.Components;
using BirthList.Web.Components.Account;
using BirthList.Web.Configuration;
using BirthList.Web.Data;
using BirthList.Web.Features.Registries;
using BirthList.Web.Services;
using Microsoft.AspNetCore.Components.Authorization;
@@ -9,10 +13,6 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using BirthList.Web.Components;
using BirthList.Web.Components.Account;
using BirthList.Web.Data;
using System.Data;
var builder = WebApplication.CreateBuilder(args);
@@ -159,6 +159,18 @@ else
}
app.UseForwardedHeaders();
var publicUrl = app.Configuration["PublicUrl"];
if (!string.IsNullOrWhiteSpace(publicUrl) && Uri.TryCreate(publicUrl, UriKind.Absolute, out var publicUri))
{
app.Use(async (context, next) =>
{
context.Request.Scheme = publicUri.Scheme;
context.Request.Host = new Microsoft.AspNetCore.Http.HostString(publicUri.Host, publicUri.IsDefaultPort ? -1 : publicUri.Port);
await next();
});
}
app.UseHttpsRedirection();
app.UseStaticFiles();
+2 -1
View File
@@ -38,5 +38,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"PublicUrl": ""
}