Repository navigation
[skip eval] feat: 游客身份(免登录使用第一步) - #390
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
免登录使用的第一步:未登录用户可以领取一个游客身份,像登录用户一样以 Bearer 令牌访问,会话照常保存在服务端,刷新或重开页面都还在。登录变成功能门槛,而不是使用门槛。额度与权益在 PR 2,前端在 PR 3。
改动
游客身份:
is_guest字段(Alembicb7d2e4f6a813,ADD COLUMN ... DEFAULT false NOT NULL)。POST /api/auth/guest,创建一个游客用户,返回 Fusion 自己签发的 HS256 令牌,有效期 365 天,签发方为fusion-guest,与统一认证服务的 RS256 令牌互不混用。认证:
get_current_user先按签发方分流。游客令牌用独立密钥验签,只能解析到is_guest=True的用户,不能冒充登录用户;游客不走统一认证服务的资料同步和单点登出检查。登录门槛:新增
require_registered_user依赖,挂到以下写操作上,游客请求返回 403LOGIN_REQUIRED:PATCH /me。读取接口不拦,游客读到的是空列表,界面不会出现 403 报错。
防刷:同一 IP 每天(北京时间)最多新建 5 个游客身份,超过返回 429。
CF-Connecting-IP、X-Real-IP、X-Forwarded-For的第一个地址、直连地址。开关与密钥:
GUEST_MODE_ENABLED(GitHub 变量,默认 false)和GUEST_TOKEN_SECRET(GitHub Secret,已用随机值创建)。部署脚本和回滚脚本都会传入这两项。SECRET_KEY:dev 没有配置它,目前用的是代码里的默认值。上线影响
GUEST_MODE_ENABLED保持 false,本 PR 上线后行为不变。PR 2 的额度限制上线前不会打开。验证
test_guest_identity.py(13 项),覆盖:require_registered_user拒绝游客。PATCH /me、文件上传、新建知识库都返回 403LOGIN_REQUIRED。test_guest_identity、test_security、test_knowledge_bases、test_core_surface、test_deploy_auth_config。另外 3 个测试文件(test_response、test_agent_trajectory_migration、test_ci_cd_permission_boundary)共 51 项通过。ALTER TABLE users ADD COLUMN is_guest BOOLEAN DEFAULT false NOT NULL。本地 SQLite 跑不了完整的迁移链(已有迁移用到 JSONB),所以没有在本地实际执行。部署时会自动执行 upgrade。CF-Connecting-IP能否到达后端。这要等 PR 2 上线后,在 dev 打开开关时实测。🤖 Generated with Claude Code