1
build / build-push (push) Successful in 27s

This commit is contained in:
wanghu
2026-09-03 20:55:10 +08:00
parent 07b817ccca
commit f43a0450ac
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using System; using System;
using System.Reflection.Metadata;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yh.Platform.Abstractions; using Yh.Platform.Abstractions;
using Yh.Platform.Auth; using Yh.Platform.Auth;
@@ -96,7 +97,19 @@ namespace YhCore.WebApi.Middleware
{ {
context.Response.StatusCode = StatusCodes.Status200OK; context.Response.StatusCode = StatusCodes.Status200OK;
context.Response.ContentType = "application/json; charset=utf-8"; context.Response.ContentType = "application/json; charset=utf-8";
throw new DException(ErrorCode.Unauthorized);
// 返回与文档导航 Challenge 一致的 CAS 登录地址(200 + JSON 而非 302,避免跨域跳转被 CORS 拦截)。
// service 指向 signin-cas 回调,与 CasAuthenticationHandler.HandleChallengeAsync 的 BuildServiceUrl 一致
// (AppBaseUrl + SignInCallbackPath),保证回调重建 service 时与登录时完全一致,ticket 校验才能通过。
var casBase = (sso["CasServerUrlPrefix"] ?? string.Empty).TrimEnd('/');
var root = string.IsNullOrEmpty(sso["AppBaseUrl"])
? (context.Request.Scheme + "://" + context.Request.Host.Value)
: sso["AppBaseUrl"].TrimEnd('/');
var callbackPath = sso["SignInCallbackPath"] ?? "/signin-cas";
var loginUrl = casBase + "/login?service=" + Uri.EscapeDataString(root + callbackPath);
await context.Response.WriteAsync("{\"code\":302,\"urlToRedirectTo\":\"" + loginUrl + "\"}");
return;
} }
// 未认证 → Challenge → 302 重定向 CAS 登录页(ticket 校验与回跳由新框架 CasAuthenticationHandler 处理) // 未认证 → Challenge → 302 重定向 CAS 登录页(ticket 校验与回跳由新框架 CasAuthenticationHandler 处理)