Fix OIDC redirect_uri mismatch behind k8s ingress (SOR.Admin)
The admin pod runs plain HTTP; the ingress terminates TLS. Without forwarded headers, ASP.NET Core built the redirect_uri as "http://control.aeternalisgames.com/signin-oidc" but Keycloak only accepts the https:// variant, causing "invalid_redirect_uri". Add UseForwardedHeaders() with XForwardedProto/Host/For before UseAuthentication so the OIDC middleware sees the correct public https scheme and hostname when constructing the callback URL. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication;
|
|||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -127,9 +128,25 @@ builder.Services.AddChatDatabase(builder.Configuration);
|
|||||||
builder.Services.AddGameDatabase(builder.Configuration);
|
builder.Services.AddGameDatabase(builder.Configuration);
|
||||||
builder.Services.AddSupportDatabase(builder.Configuration);
|
builder.Services.AddSupportDatabase(builder.Configuration);
|
||||||
|
|
||||||
|
// ── Forwarded headers ─────────────────────────────────────────────────────
|
||||||
|
// The pod runs plain HTTP behind a TLS-terminating ingress. Without this,
|
||||||
|
// ASP.NET Core builds the OIDC redirect_uri as "http://..." which Keycloak
|
||||||
|
// rejects. Clearing KnownNetworks/KnownProxies trusts any upstream proxy —
|
||||||
|
// safe because the pod is only reachable from within the cluster.
|
||||||
|
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||||
|
{
|
||||||
|
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost;
|
||||||
|
options.KnownNetworks.Clear();
|
||||||
|
options.KnownProxies.Clear();
|
||||||
|
});
|
||||||
|
|
||||||
// ── HTTP pipeline ─────────────────────────────────────────────────────────
|
// ── HTTP pipeline ─────────────────────────────────────────────────────────
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Must come before UseAuthentication so the scheme/host are correct when
|
||||||
|
// the OIDC middleware constructs the redirect_uri.
|
||||||
|
app.UseForwardedHeaders();
|
||||||
|
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/Error");
|
app.UseExceptionHandler("/Error");
|
||||||
|
|||||||
Reference in New Issue
Block a user