第一期骨架:登录、实例登记、多机总览、内嵌/新标签打开。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-01 10:54:07 +08:00
parent 55e77d6b2b
commit d20acaf852
17 changed files with 881 additions and 2 deletions
+34
View File
@@ -0,0 +1,34 @@
"""SSO 打开链(与 crypto_okx lib.hub.hub_bridge_auth 算法一致)."""
from __future__ import annotations
import hashlib
import hmac
import time
from urllib.parse import urlencode
def make_sso_token(bridge_token: str, *, ttl_sec: int = 120) -> str:
exp = int(time.time()) + max(30, int(ttl_sec))
payload = str(exp)
sig = hmac.new(
bridge_token.encode("utf-8"),
payload.encode("utf-8"),
hashlib.sha256,
).hexdigest()
return f"{payload}.{sig}"
def build_embed_open_url(
base_url: str,
*,
bridge_token: str,
embed_path: str = "/embed",
ttl_sec: int = 120,
) -> str:
root = (base_url or "").rstrip("/")
path = embed_path or "/embed"
if not path.startswith("/"):
path = "/" + path
token = make_sso_token(bridge_token, ttl_sec=ttl_sec)
q = urlencode({"token": token, "next": path})
return f"{root}/hub_sso?{q}"