修复中控内嵌:跨站 Cookie 被拦时用 embed_sso 维持登录。
SSO 写入 sessionStorage,fetch 自动带 X-Hub-Embed-SSO,避免期权链 API 401。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -83,6 +83,25 @@ def build_embed_open_url(
|
||||
return f"{root}/hub_sso?{q}"
|
||||
|
||||
|
||||
def extract_embed_sso(request) -> str:
|
||||
"""中控 iframe 内用的短期会话令牌(Cookie 被拦时的后备)."""
|
||||
raw = (request.headers.get("X-Hub-Embed-SSO") or "").strip()
|
||||
if raw:
|
||||
return raw
|
||||
return (request.args.get("embed_sso") or "").strip()
|
||||
|
||||
|
||||
def hub_embed_sso_ok(request) -> bool:
|
||||
tok = extract_embed_sso(request)
|
||||
return bool(tok and verify_sso_token(tok))
|
||||
|
||||
|
||||
def make_embed_session_token(bridge_token: str | None = None, *, ttl_sec: int = 604800) -> str:
|
||||
"""嵌入会话令牌(默认 7 天),算法与 SSO 相同."""
|
||||
secret = (bridge_token if bridge_token is not None else hub_bridge_token()).strip()
|
||||
return make_sso_token(secret, ttl_sec=ttl_sec)
|
||||
|
||||
|
||||
def frame_ancestors_header_value() -> Optional[str]:
|
||||
"""
|
||||
HUB_EMBED_FRAME_ANCESTORS: 空格分隔 Origin,如 https://hub.local http://192.168.1.10:5100
|
||||
|
||||
Reference in New Issue
Block a user