From 8abba50e0e2769b981d646f560e10b46327072d0 Mon Sep 17 00:00:00 2001 From: wanghu Date: Sat, 5 Sep 2026 16:17:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0deugUser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Auth/Cas/YhCasAuthServiceCollectionExtensions.cs | 2 +- src/YhCore.WebApi/Startup.cs | 4 ++++ src/YhCore.WebApi/appsettings.json | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/YhCore.WebApi/Auth/Cas/YhCasAuthServiceCollectionExtensions.cs b/src/YhCore.WebApi/Auth/Cas/YhCasAuthServiceCollectionExtensions.cs index 20fee70..47523a8 100644 --- a/src/YhCore.WebApi/Auth/Cas/YhCasAuthServiceCollectionExtensions.cs +++ b/src/YhCore.WebApi/Auth/Cas/YhCasAuthServiceCollectionExtensions.cs @@ -44,7 +44,7 @@ namespace YhCore.WebApi.Auth var auth = configuration.GetSection(YhAuthOptions.SectionName).Get() ?? new YhAuthOptions(); options.Cookie.Name = auth.CookieName; options.Cookie.HttpOnly = true; - options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax; + options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.None; // 会话票据:TicketDataFormat 把票据存服务端,Cookie 只写 32 位 key; // IsPersistent=false(CasAuthenticationHandler)会话 Cookie,关闭浏览器即失效; // SlidingExpiration=false 固定过期,不滑动续期。 diff --git a/src/YhCore.WebApi/Startup.cs b/src/YhCore.WebApi/Startup.cs index 4ceb4db..909e4c0 100644 --- a/src/YhCore.WebApi/Startup.cs +++ b/src/YhCore.WebApi/Startup.cs @@ -230,6 +230,10 @@ namespace YhCore.WebApi app.UseMiddleware(); // 0. 接口访问日志(唯一日志出口) app.UseMiddleware(); // 1. 异常兜底(异常摘要并入接口日志) app.UseAuthentication(); // 2. CAS ticket 校验 + Cookie 恢复(Yh.Platform.Auth) + // 2.5 DebugUser 模拟登录(开关 yh:auth:DebugUserEnabled,默认关):本地前端直连部署后端的 + // 跨域联调身份方案——Cookie 按 host 隔离导致线上登录态无法回流 localhost 页面请求, + // 以 DebugUser 请求头承载身份绕开。必须位于认证之后、SSO 保护之前。 + app.UseMiddleware(); app.UseMiddleware(); // 3. SSO 路径保护(未认证 → 302 CAS;认证通过后才有用户身份) app.UseYhUserContext(); // 4. 新框架用户上下文:BoaUserContext + UserContextHolder(LoginUser) // 5. 应用间签名(oapi 渠道)。必须排在 UseYhUserContext 之后: diff --git a/src/YhCore.WebApi/appsettings.json b/src/YhCore.WebApi/appsettings.json index ce42296..f8eb830 100644 --- a/src/YhCore.WebApi/appsettings.json +++ b/src/YhCore.WebApi/appsettings.json @@ -14,7 +14,8 @@ "auth": { "Enabled": true, "CookieExpireMinutes": 120, - "cookieName": ".yh.auth" + "cookieName": ".yh.auth", + "DebugUserEnabled": true }, "sso": { "Enabled": true,