forked from d-cloud/d-wiki
## 改动 - 移除内置的 auth 模块,改为调用 d-auth CLI - 添加登录拦截器,保护 index/compile/dream/search/get 命令 - 添加 d-auth 作为依赖项 ## 认证流程 1. 用户执行需要认证的命令 2. d-wiki 调用 d-auth check 检查登录状态 3. 未登录则拦截并提示用户登录 4. 已登录则正常执行命令 ## 相关文档 见 docs/AUTH.md Co-Authored-By: Claude <noreply@anthropic.com>
2.6 KiB
2.6 KiB
d-wiki 认证集成说明
概述
d-wiki 现已集成 d-auth 认证系统,用户需要先登录才能使用知识库相关功能。
认证架构
d-wiki CLI ──调用──> d-auth CLI ──存储──> macOS Keychain
│ │
│ └──验证──> JWKS (cloud.d-robotics.cc)
│
└──拦截未登录请求──> 提示用户登录
依赖关系
d-wiki 依赖 d-auth 包,安装 d-wiki 时会自动安装 d-auth:
# pyproject.toml
dependencies = [
"d-auth>=0.1.0",
]
受认证保护的命令
以下命令需要登录才能使用:
d-wiki indexd-wiki compiled-wiki dreamd-wiki searchd-wiki get
以下命令无需登录:
d-wiki statusd-wiki auth login/logout/status
使用方式
安装
# 安装 d-wiki(会自动安装 d-auth)
pip install git+https://gitea.d-robotics.cc/d-cloud/d-wiki.git
# 或单独安装 d-auth
pip install git+https://gitea.d-robotics.cc/d-cloud/d-auth.git
登录
# 方式一:通过 d-wiki 登录
d-wiki auth login
# 方式二:直接使用 d-auth 登录
d-auth login
登录流程:
- CLI 启动本地 HTTP 服务器(随机端口)
- 打开浏览器访问 SSO 登录页
- 用户在浏览器中完成登录
- SSO 跳转回本地回调地址,传递 token
- CLI 将 token 存入 macOS Keychain
查看登录状态
d-wiki auth status
# 或
d-auth status
输出示例:
{
"logged_in": true,
"username": "admin&dcloud",
"user_id": "e0111193-da12-45c2-94b3-e5854ea69192",
"expires_at": "2026-06-09T13:51:41+00:00"
}
登出
d-wiki auth logout
# 或
d-auth logout
使用知识库功能
# 登录后可正常使用
d-wiki search --kb mykb --query "测试查询"
# 未登录时会被拦截
d-wiki search --kb mykb --query "测试查询"
# 输出: {"status": "error", "error": "D_WIKI_NOT_LOGGED_IN: 请先运行 'd-auth login' 登录"}
Token 存储
Token 存储在 macOS Keychain 中:
- Service:
d-auth - Account:
user-center-jwt
Token 验证
登录状态通过 JWKS 验证:
- JWKS URL:
https://cloud.d-robotics.cc/.well-known/jwks.json - 算法: RS256
- Key ID:
yx-yyds-key
Token 过期处理
当 token 过期或无效时:
d-auth status自动检测并清除过期 token- 返回
logged_in: false - 用户需重新登录