返回顶部
o

oauth-providersOAuth提供商

Adds an "OAuth" settings tab to the OpenClaw Control UI for connecting AI model providers. Supports Anthropic Claude Pro/Max subscription tokens (setup-token flow), OpenAI Codex PKCE OAuth with manual-paste fallback for WSL2, and API keys for Anthropic, OpenAI, Google (Gemini), and OpenRouter. Includes auth profile order troubleshooting, badge rendering logic, and architecture reference for the auth-profiles system. Credentials are stored encrypted in auth-profiles.json and secrets.json.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.1.0
安全检测
已通过
304
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

oauth-providers

OAuth 提供商选项卡

为 OpenClaw 控制界面添加了一个精美的 OAuth 设置选项卡。

安装内容

文件用途
ui/src/ui/views/ai-providers.tsLit HTML 视图 — 提供商卡片、模式选项卡、OAuth 加载动画、手动粘贴字段
ui/src/ui/controllers/ai-providers.ts
状态管理、RPC 调用、提供商目录 | | src/gateway/server-methods/auth-login.ts | 所有认证流程的网关 RPC 处理器 |

以及以下文件的接线变更:

  • - ui/src/ui/app.ts — 6 个 @state() 属性
  • ui/src/ui/app-render.ts — state.tab === ai-providers 的渲染块
  • ui/src/ui/app-settings.ts — 选项卡加载触发器
  • ui/src/ui/navigation.ts — Tab 类型、TABPATHS、iconForTab
  • src/gateway/server-methods.ts — 注册 authLoginHandlers
  • src/gateway/server-methods/plugins-ui.ts — BUILTINUI_VIEWS 条目
  • ui/src/i18n/locales/en.ts — ai-providers 标签(OAuth)和副标题

认证流程

OpenAI — Codex PKCE OAuth

  • - 按钮通过 openUrl() 打开系统浏览器
  • 回调在 localhost:1455/auth/callback 上捕获
  • 调用 @mariozechner/pi-ai 中的 loginOpenAICodex()
  • 凭据由 writeOAuthCredentials() + applyAuthProfileConfig() 写入
  • WSL2 手动粘贴回退:在 WSL2 上,Windows 无法访问 127.0.0.1:1455。界面显示一个粘贴字段,用户可以在其中粘贴完整的重定向 URL(http://localhost:1455/auth/callback?code=...&state=...)。网关 RPC auth.login.openai-codex.submit-code 解析一个延迟的 Promise,该 Promise 通过 onManualCodeInput 与本地回调服务器竞争。
  • 会话状态:aiProvidersOauthSessionId 由 startOpenAICodexOAuth 设置 → 由 aiProvidersSubmitCode 用于调用 RPC

Anthropic — 订阅令牌(setup-token)

  • - 用户在终端中运行 claude setup-token 生成 sk-ant-oat01-... 令牌
  • 将令牌粘贴到界面中
  • 由 validateAnthropicSetupToken() 验证,通过 buildTokenProfileId() + upsertAuthProfile() 存储
  • 自动检测按钮:从 ~/.claude/.credentials.json(在 claudeAiOauth 下)读取现有的 accessToken,并通过 auth.login.anthropic-auto RPC 存储
  • ⚠️ 重要提示:Anthropic 已阻止某些在 Claude Code 之外的订阅使用。文档警告:此凭据仅授权用于 Claude Code。 设置令牌支持仅为技术兼容性,存在政策风险。如果收到未授权错误,则需要 API 密钥。

API 密钥(所有提供商)

  • - 通过现有的 secrets.write RPC 加密到 ~/.openclaw/secrets.json
  • 环境变量:ANTHROPICAPIKEY、OPENAIAPIKEY、GOOGLEAPIKEY、OPENROUTERAPIKEY

网关 RPC

方法描述
auth.login.status列出所有已配置的认证配置文件
auth.login.anthropic-token
验证并存储 Anthropic 设置令牌 | | auth.login.anthropic-auto | 从 ~/.claude/.credentials.json 自动检测令牌 | | auth.login.openai-codex | 运行 PKCE OAuth(打开浏览器) | | auth.login.openai-codex.submit-code | 手动粘贴重定向 URL(WSL2 回退) | | auth.login.remove | 按 profileId 删除配置文件 |

认证徽章系统

聊天界面在助手消息旁边显示一个徽章,指示使用了哪种认证方法。

徽章渲染(grouped-render.ts)

profileId 模式徽章CSS 类
mode:oauthOAuth(绿色)auth-badge--oauth
包含 :manual 或 claude-cli 或以 anthropic:oat 开头
OAuth(绿色) | auth-badge--oauth | | 以 anthropic: 开头(全捕获) | API(蓝色) | auth-badge--api | | 以 openai: 开头 | 回退 | auth-badge--fallback | | 其他所有情况 | API | auth-badge--fallback |

徽章由消息组中的 group.authProfileId 决定。如果激活了错误的配置文件,则会显示错误的徽章。

完整函数请参见 references/auth-badge.ts.excerpt

认证配置文件顺序 — 架构与故障排除

配置文件选择的工作原理

网关通过 src/agents/auth-profiles/order.ts 中的 resolveAuthProfileOrder() 选择要使用的认证配置文件:

storedOrder (auth-profiles.json) → 优先
configuredOrder (openclaw.json) → 无存储顺序时的回退
explicitProfiles (配置键) → 无显式顺序时的回退
storeProfiles (存储中的所有) → 最后手段

关键:auth-profiles.json 的顺序始终优先于 openclaw.json 的顺序。如果 auth-profiles.json 有陈旧的 order 数组,则永远不会考虑 openclaw.json 中的正确顺序。

关键代码请参见 references/auth-order.ts.excerpt

常见问题:陈旧顺序/幽灵配置文件

症状:即使订阅令牌配置正确,徽章仍显示API或回退。

原因:auth-profiles.json 的 order 数组引用了不存在的配置文件(例如来自旧设置的 anthropic:manual)。现有的配置文件(如 anthropic:default)被选中,而不是订阅令牌配置文件。

诊断
bash

检查当前认证状态


openclaw models status

检查 auth-profiles.json 实际内容

python3 -c import json with open($HOME/.openclaw/agents/main/agent/auth-profiles.json) as f: d = json.load(f) print(order:, d.get(order)) print(lastGood:, d.get(lastGood)) print(profiles:, list(d[profiles].keys()))

修复
bash

选项 1:删除陈旧顺序,使 openclaw.json 成为权威


python3 -c
import json
path = $HOME/.openclaw/agents/main/agent/auth-profiles.json
with open(path) as f: d = json.load(f)
d.pop(order, None)
d.pop(lastGood, None)
with open(path, w) as f: json.dump(d, f, indent=2)
print(已删除陈旧顺序)

选项 2:通过 CLI 设置顺序(写入 auth-profiles.json)

openclaw models auth order set --provider anthropic anthropic:claude-cli anthropic:default

然后重启网关

(sleep 3 && systemctl --user restart openclaw-gateway) &

为什么选项 1 更优:CLI 写入 auth-profiles.json,但网关重启或其他进程可能会覆盖它。删除存储的顺序可以让 openclaw.json(即规范配置)成为权威。

修复逻辑

resolveAuthProfileOrder() 有一个修复路径(第 96-100 行):如果基础顺序中的所有配置文件在存储中都缺失,它会扫描存储中该提供商的所有配置文件。但这仅在每个配置文件都缺失时触发——如果即使有一个存在(如 anthropic:default),修复也不会启动。

配置验证

确保 openclaw.json 具有正确的认证部分:
json
{
auth: {
profiles: {
anthropic:claude-cli: { provider: anthropic, mode: oauth },
anthropic:default: { provider: anthropic, mode: api_key }
},
order: {
anthropic: [anthropic:claude-cli, anthropic:default]
}
}
}

openclaw.json 配置文件中的 mode 字段会与

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 oauth-providers-1776207287 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 oauth-providers-1776207287 技能

通过命令行安装

skillhub install oauth-providers-1776207287

下载

⬇ 下载 oauth-providers v1.1.0(免费)

文件大小: 17.57 KB | 发布时间: 2026-4-15 10:36

v1.1.0 最新 2026-4-15 10:36
WSL2 manual-paste fallback, Anthropic auto-detect, auth order architecture docs, badge rendering reference, stale order troubleshooting guide

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部