-
Notifications
You must be signed in to change notification settings - Fork 0
Agents Vibe Coding Guide
何家欢 edited this page Jun 17, 2026
·
3 revisions
本页专门给 AI coding agents、自动化编码助手和 vibe coding 工作流使用。目标是让 agent 快速理解项目边界,安全扩展功能,而不是凭感觉乱改认证核心。
Passkey-Auth 是一个 Flask + SQLite + WebAuthn 的现代 passkey OAuth/SSO 认证服务,强调用户优先 UI、标准 OAuth code flow、link challenge flow 和服务端安全校验。
优先保持这些不变量:
- WebAuthn challenge 必须保存在后端 session 中,并在 verify 后清理。
- OAuth code 必须一次性消费。
- Link challenge 必须一次性消费。
-
state必须由发起方生成并在 callback 校验。 -
status=success不可信。 -
client_secret和 server token 不得进入前端。 -
PASSKEY_ORIGIN必须与浏览器 origin 匹配。 - 注册默认关闭。
passkey_demo/app.py
Flask app、路由、OAuth flow、challenge flow、server verify
passkey_demo/config.py
默认配置和环境变量覆盖
passkey_demo/storage.py
SQLite schema、用户、credential、code、challenge 存储
passkey_demo/webauthn_service.py
WebAuthn options 生成和 verify 封装
passkey_demo/register_client.py
动态下发的注册前端模块
passkey_demo/static/main.js
首页 Logo 交互、无用户名登录、注册面板解锁
passkey_demo/static/oauth_authorize.js
OAuth/Challenge Auth WebUI 自动 passkey 验证
passkey_demo/templates/
共享品牌外壳、首页、OAuth 页面、第三方示例、link challenge 示例
tests/
配置、注册保护、OAuth、link challenge 测试
- 读相关文件,不要全局重构。
- 明确要改的是 UI、WebAuthn、OAuth、存储还是配置。
- 小步修改。
- 跑测试:
.venv/bin/python -m unittest discover -s tests -v- 如果改了前端,启动本地服务并用浏览器验证:
PORT=5003 PASSKEY_ORIGIN=http://localhost:5003 .venv/bin/python -m passkey_demo.app位置:
passkey_demo/app.py::_oauth_client
passkey_demo/config.py
建议:
- 单 client 部署使用
PASSKEY_OAUTH_CLIENT_ID、PASSKEY_OAUTH_CLIENT_SECRET、PASSKEY_OAUTH_CLIENT_NAME和PASSKEY_OAUTH_REDIRECT_URIS。 - 内置示例页面也走同一套标准 OAuth client 管道,不要再为 demo 单独开一条 client 校验路径。
- 旧的
PASSKEY_OAUTH_DEMO_*只是兼容别名。 - 多 client 不要继续堆环境变量;新增
oauth_clients表或配置文件。 - 生产多 client 存
client_secret_hash,不要明文。
建议新增:
oauth_refresh_tokens
- token_hash
- client_id
- user_id
- created_at
- expires_at
- revoked_at
不要复用 access token serializer 当 refresh token 存储。
建议新增独立 blueprint 或模块:
passkey_demo/admin.py
templates/admin_*.html
必须增加管理员认证,不要把注册开关当管理员认证。
优先保持 PasskeyStore 方法接口不变:
get_user_by_username
get_user_by_id
get_user_by_handle
save_credential
create_oauth_authorization_code
consume_oauth_authorization_code
create_oauth_challenge_request
complete_oauth_challenge_request
consume_oauth_challenge_request
这样 app 层不用大改。
位置:
templates/index.html
templates/brand_page.html
templates/_brand.html
templates/oauth_authorize.html
static/styles.css
static/oauth.css
static/main.js
static/oauth_authorize.js
约束:
- 保持 Auth WebUI 极简。
- 不要在 OAuth callback URL 或普通 UI 响应中暴露不必要用户信息。
- 表单、状态和按钮在移动端不能溢出。
- 保持暗色模式。
建议记录:
- OAuth authorize start
- OAuth token exchange success/fail
- Challenge create/complete/consume
- Registration attempt
- Login verify success/fail
不要记录:
- raw credential
- client secret
- access token
- challenge result token
- full session cookie
不要做这些:
- 把
PASSKEY_REGISTRATION_ENABLED默认改成 true。 - 在前端保存 client secret。
- callback 只检查
status=success就登录。 - 让 authorization code 可重复使用。
- 删除
state校验。 - 为了方便测试关闭 origin/RP ID 校验。
- 把 SQLite 数据库或
.env加进 git。 - 在 Wiki 或 README 中写入真实密钥。
每个功能至少加一种测试:
| 功能 | 测试方向 |
|---|---|
| 配置 | 默认值、环境变量覆盖 |
| 注册 | 默认关闭、开启后可解锁 |
| OAuth | authorize 接受合法 callback、拒绝恶意 callback |
| Callback | state 错误失败 |
| Token | code 可换 token、重复使用失败 |
| Challenge | 创建、完成、callback 成功、重放失败 |
| 安全 | 用户名和 passkey 不匹配时拒绝 |
Inspect passkey_demo/app.py and passkey_demo/storage.py.
Add persistent OAuth client storage without changing current standard single-client behavior.
Keep _oauth_client API shape compatible and keep example pages using the standard pipeline.
Add tests for multiple redirect URIs and invalid clients.
Run unittest.
Read README.md, docs/oauth-integration.md, and passkey_demo/config.py.
Write a deployment page covering HTTPS, RP ID, origin, secrets, database path, reverse proxy, and public repo safety.
Do not add real secrets.
Inspect templates/oauth_authorize.html, static/styles.css, and static/oauth_authorize.js.
Improve UI while keeping automatic passkey invocation and existing data-* attributes.
Verify desktop and mobile layout.
Run tests.
这个项目适合“边跑边改”的节奏,但认证代码不要只凭视觉满意就结束。每次 vibe coding 结束前至少做:
.venv/bin/python -m unittest discover -s tests -v
git diff
rg -n -uu "real-domain\\.example|github-token-prefix|openai-key-prefix|private-key-marker|\\.env" .最后确认:
- UI 体验变好了
- 安全不变量没破
- 测试覆盖新增路径
- 文档同步更新