添加deugUser

This commit is contained in:
wanghu
2026-09-05 16:17:42 +08:00
parent 3ac70fb699
commit 8abba50e0e
3 changed files with 7 additions and 2 deletions
@@ -44,7 +44,7 @@ namespace YhCore.WebApi.Auth
var auth = configuration.GetSection(YhAuthOptions.SectionName).Get<YhAuthOptions>() ?? 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 固定过期,不滑动续期。
+4
View File
@@ -230,6 +230,10 @@ namespace YhCore.WebApi
app.UseMiddleware<ApiAccessLogMiddleware>(); // 0. 接口访问日志(唯一日志出口)
app.UseMiddleware<GlobalExceptionMiddleware>(); // 1. 异常兜底(异常摘要并入接口日志)
app.UseAuthentication(); // 2. CAS ticket 校验 + Cookie 恢复(Yh.Platform.Auth)
// 2.5 DebugUser 模拟登录(开关 yh:auth:DebugUserEnabled,默认关):本地前端直连部署后端的
// 跨域联调身份方案——Cookie 按 host 隔离导致线上登录态无法回流 localhost 页面请求,
// 以 DebugUser 请求头承载身份绕开。必须位于认证之后、SSO 保护之前。
app.UseMiddleware<DebugUserMiddleware>();
app.UseMiddleware<SsoProtectionMiddleware>(); // 3. SSO 路径保护(未认证 → 302 CAS;认证通过后才有用户身份)
app.UseYhUserContext(); // 4. 新框架用户上下文:BoaUserContext + UserContextHolder(LoginUser)
// 5. 应用间签名(oapi 渠道)。必须排在 UseYhUserContext 之后:
+2 -1
View File
@@ -14,7 +14,8 @@
"auth": {
"Enabled": true,
"CookieExpireMinutes": 120,
"cookieName": ".yh.auth"
"cookieName": ".yh.auth",
"DebugUserEnabled": true
},
"sso": {
"Enabled": true,