Skip to main content

Module auth

Module auth 

Source
Expand description

REST API 的 Bearer Token 鉴权

两种模式:

  • 未配置 KeyStore:完全不鉴权(保持旧行为,启动日志 warn)
  • 配置了 KeyStore:所有 /api/* 请求必须带 Authorization: Bearer <plaintext>, 且对应 key 必须有下表要求的 scope

路由 → scope 映射(硬编码,后续可做成配置):

路径前缀所需 scope
/api/global-state, /api/user-info, /api/quote-rights, /api/delay-statistics, /api/market-stateqot:read
/api/quote / /api/kline / /api/orderbook / /api/broker / /api/ticker / /api/rt / /api/snapshot / /api/static-info / /api/plate-* / /api/reference / /api/owner-plate / /api/option-chain / /api/warrant / /api/capital-* / /api/user-security / /api/stock-filter / /api/ipo-list / /api/future-info / /api/history-kline / /api/subscribe / /api/sub-infoqot:read
/api/accounts / /api/funds / /api/positions / /api/orders / /api/order-fills / /api/history-orders / /api/history-order-fills / /api/max-trd-qtys / /api/margin-ratio / /api/order-fee / /api/sub-acc-pushacc:read
/api/order (POST = 下单) / /api/modify-order / /api/unlock-tradetrade (super-scope, v1.4.90 P1-A)

v1.4.90 P1-A: TRADE 列从硬编码 Scope::TradeReal 改为 super-scope Scope::Trade。middleware 用 [scope_satisfied] 接受持有 TradeReal/TradeSimulate/TradeUnlock 任一即过,handler 层再用真实 scopes 二次校验 env (sim 不允许下真实单等)。修 trade:simulate / trade:unlock key 调对应 endpoint 被 403 误拒。

Structs§

AuthState
REST auth middleware 的组合 state:KeyStore(谁能进)+ RuntimeCounters(限额)
RestAdapter
v1.4.106 D1 5a: REST surface adapter — 把 pipeline AuthDecision::Reject 翻成 axum Response.

Functions§

bearer_auth
axum middleware:Bearer Token + scope 校验