OpenClaw 驗證憑證設定指南:解析與除錯規則
處理 Auth 憑證常常讓人抓狂,有時候本地端跑得好好的,部署後卻因為 Token 過期或設定不對直接掛掉。為了讓你開發更順手,我們統一了憑證的處理邏輯,確保你在不同工具間看到的結果都是一致的。
這份文件定義了在以下工具中使用的標準憑證資格與解析語義:
resolveAuthProfileOrderresolveApiKeyForProfilemodels status --probedoctor-auth
目標是讓選擇時與執行時的行為保持一致。
穩定狀態碼 (Stable Reason Codes)
Section titled “穩定狀態碼 (Stable Reason Codes)”okmissing_credentialinvalid_expiresexpiredunresolved_ref
Token 憑證 (Token Credentials)
Section titled “Token 憑證 (Token Credentials)”Token 憑證 (type: "token") 支援內聯的 token 以及 tokenRef(或兩者同時存在)。
資格規則 (Eligibility rules)
Section titled “資格規則 (Eligibility rules)”- 當
token與tokenRef同時缺失時,該 Token Profile 為無效。 expires是選填項。- 如果有提供
expires,它必須是一個大於0的有限數字。 - 如果
expires無效(例如NaN、0、負數、非有限數值或類型錯誤),該 Profile 會被標記為invalid_expires且不具備資格。 - 如果
expires的時間點已過去,該 Profile 會被標記為expired且不具備資格。 - 使用
tokenRef並不會跳過expires的驗證。
解析規則 (Resolution rules)
Section titled “解析規則 (Resolution rules)”- 解析器的語義在
expires方面與資格規則一致。 - 對於符合資格的 Profile,Token 內容可以從內聯數值或
tokenRef中解析出來。 - 無法解析的引用(Refs)會在
models status --probe的輸出中產生unresolved_ref。
OAuth SecretRef 策略防護 (OAuth SecretRef Policy Guard)
Section titled “OAuth SecretRef 策略防護 (OAuth SecretRef Policy Guard)”- SecretRef 輸入僅適用於靜態憑證。
- 如果 Profile 憑證是
type: "oauth",則該 Profile 的憑證內容不支援 SecretRef 物件。 - 如果
auth.profiles.<id>.mode設定為"oauth",系統會拒絕該 Profile 使用基於 SecretRef 的keyRef或tokenRef輸入。 - 違反此規則將導致啟動或重新載入 Auth 解析路徑時發生硬錯誤(Hard failures)。
相容舊版的訊息 (Legacy-Compatible Messaging)
Section titled “相容舊版的訊息 (Legacy-Compatible Messaging)”為了確保腳本相容性,Probe 錯誤會保留第一行內容不變:
Auth profile credentials are missing or expired.
後續行數可能會加入對人類更友好的詳細資訊以及穩定的狀態碼。
想要快速完成設定嗎?試試我們的 AI Setup Assistant。
OpenClaw Expert
還是卡住了?
如果這篇文件沒有解決你的情境,直接問 OpenClaw Expert,拿到可執行步驟。