diff --git a/Server/Directory.Packages.props b/Server/Directory.Packages.props index 8acb406..ecbb97b 100644 --- a/Server/Directory.Packages.props +++ b/Server/Directory.Packages.props @@ -25,6 +25,8 @@ + + diff --git a/Server/src/SOR.Admin/Program.cs b/Server/src/SOR.Admin/Program.cs index 463c235..6d6d538 100644 --- a/Server/src/SOR.Admin/Program.cs +++ b/Server/src/SOR.Admin/Program.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Identity; @@ -141,13 +142,20 @@ builder.Services.AddIdentityCore(options => builder.Services.AddRazorPages(); // ── Redis ────────────────────────────────────────────────────────────────── -builder.Services.AddSingleton(_ => -{ - var redisConnectionString = builder.Configuration.GetConnectionString("Redis") ?? "localhost:6379"; - var redisOptions = ConfigurationOptions.Parse(redisConnectionString); - redisOptions.AbortOnConnectFail = false; - return ConnectionMultiplexer.Connect(redisOptions); -}); +// Create the connection eagerly so it can be shared with DataProtection below. +var redisConnectionString = builder.Configuration.GetConnectionString("Redis") ?? "localhost:6379"; +var redisConfig = ConfigurationOptions.Parse(redisConnectionString); +redisConfig.AbortOnConnectFail = false; +var redis = ConnectionMultiplexer.Connect(redisConfig); +builder.Services.AddSingleton(redis); + +// ── DataProtection (Redis-backed) ───────────────────────────────────────── +// Persist DataProtection keys in Redis so all pod replicas share the same key +// ring. Without this, cookies set by pod A cannot be decrypted by pod B, +// causing a redirect loop: OIDC flow completes → cookie set → redirect → +// different pod → cookie unreadable → user appears anonymous → loop. +builder.Services.AddDataProtection() + .PersistKeysToStackExchangeRedis(redis, "SOR.Admin:DataProtection-Keys"); // ── CDN client ──────────────────────────────────────────────────────────── builder.Services.AddCdnClient(builder.Configuration); diff --git a/Server/src/SOR.Admin/SOR.Admin.csproj b/Server/src/SOR.Admin/SOR.Admin.csproj index a96dde5..6fb93fa 100644 --- a/Server/src/SOR.Admin/SOR.Admin.csproj +++ b/Server/src/SOR.Admin/SOR.Admin.csproj @@ -15,6 +15,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive +