增加反代
This commit is contained in:
@@ -35,7 +35,9 @@ from hub_web_auth import (
|
||||
expected_username,
|
||||
verify_credentials,
|
||||
)
|
||||
from hub_auth import HUB_SSO_TTL_SEC, mint_hub_sso_token, safe_next_path
|
||||
from url_public import browser_url, default_review_url, public_origin
|
||||
from urllib.parse import urlencode
|
||||
|
||||
try:
|
||||
from exchange_orders import symbols_match as _symbols_match
|
||||
@@ -52,7 +54,7 @@ HUB_BRIDGE_TOKEN = (os.getenv("HUB_BRIDGE_TOKEN") or os.getenv("CONTROL_TOKEN")
|
||||
_trust_raw = (os.getenv("HUB_TRUST_LAN", "true") or "").strip().lower()
|
||||
HUB_TRUST_LAN = _trust_raw not in ("0", "false", "no", "off")
|
||||
DIR = Path(__file__).resolve().parent
|
||||
HUB_BUILD = "20260525-okx-tpsl2"
|
||||
HUB_BUILD = "20260525-hub-sso"
|
||||
HUB_AGENT_TIMEOUT = float(os.getenv("HUB_AGENT_TIMEOUT", "8"))
|
||||
HUB_FLASK_TIMEOUT = float(os.getenv("HUB_FLASK_TIMEOUT", "10"))
|
||||
_board_key_prices_raw = (os.getenv("HUB_BOARD_KEY_PRICES", "true") or "").strip().lower()
|
||||
@@ -523,6 +525,40 @@ async def api_monitor_board():
|
||||
}
|
||||
|
||||
|
||||
def _require_hub_logged_in(request: Request) -> None:
|
||||
if password_required() and not validate_session_token(request.cookies.get(SESSION_COOKIE)):
|
||||
raise HTTPException(status_code=401, detail="未登录中控")
|
||||
|
||||
|
||||
@app.get("/api/instance/open-url")
|
||||
def api_instance_open_url(request: Request, exchange_id: str, next: str = "/"):
|
||||
"""已登录中控时生成实例 SSO 打开链接(2h 有效、单次使用,复用 HUB_BRIDGE_TOKEN)。"""
|
||||
_require_hub_logged_in(request)
|
||||
if not HUB_BRIDGE_TOKEN:
|
||||
raise HTTPException(status_code=503, detail="未配置 HUB_BRIDGE_TOKEN,无法签发实例打开链接")
|
||||
ex = _find_exchange(exchange_id)
|
||||
if not ex:
|
||||
raise HTTPException(status_code=404, detail="未知交易所 id")
|
||||
base = browser_url((ex.get("flask_url") or "").strip()).rstrip("/")
|
||||
if not base:
|
||||
raise HTTPException(status_code=400, detail="该账户未配置 flask_url")
|
||||
ex_key = (ex.get("key") or "").strip().lower()
|
||||
if not ex_key:
|
||||
raise HTTPException(status_code=400, detail="该账户缺少 key(用于 SSO 校验)")
|
||||
nxt = safe_next_path(next)
|
||||
token = mint_hub_sso_token(ex_key, nxt)
|
||||
if not token:
|
||||
raise HTTPException(status_code=503, detail="签发 SSO 失败")
|
||||
q = urlencode({"token": token, "next": nxt})
|
||||
return {
|
||||
"ok": True,
|
||||
"url": f"{base}/hub-sso?{q}",
|
||||
"expires_in": HUB_SSO_TTL_SEC,
|
||||
"exchange_id": exchange_id,
|
||||
"exchange_key": ex_key,
|
||||
}
|
||||
|
||||
|
||||
class CloseAllBody(BaseModel):
|
||||
exclude_ids: list[str] = Field(default_factory=list)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user