Skip to content

fix(auth): Cookie 快照方法缺失时安全降级 + Google 账号可选 - #191

Merged
genz27 merged 1 commit into
TheSmallHanCat:mainfrom
genz27:fix/cookie-snapshot-compat-optional-account
Oct 23, 2026
Merged

genz27 merged 1 commit into
TheSmallHanCat:mainfrom
genz27:fix/cookie-snapshot-compat-optional-account

Conversation

@genz27

@genz27 genz27 commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

问题

添加 Google Cookie 时失败:

添加失败: Google Cookie 验证失败:'FlowClient' object has no attribute 'get_updated_flow_cookies'

成因

828b620 把 Cookie 轮换快照方法放进了 FlowFrontendMixin(flow_frontend.py):

  • get_updated_flow_cookies
  • _remember_flow_cookies
  • _update_flow_cookie_jar

而 flow_client.py / flow_current.py 里已有调用点。部署方如果用自定义/旧版 flow_frontend.py 整文件覆盖(常见做法:挂载 patched 文件),
这些方法会一起消失,调用点直接 AttributeError,整条添加 Cookie 流程失败。

修复

  1. 调用点改为安全取值(getattr + 降级返回原始 Cookie 串):
    • flow_current.py st_to_at
    • flow_client.py _build_team_captcha_cookie_map
    • flow_client.py _update_flow_cookie_jar 调用处做存在性判断
      有实现时行为完全不变,只是不再因覆盖而崩。
  2. Google 账号改为可选(需求:不一定填):
    • AddTokenRequest / PluginTokenUpdateRequest 的 login_account 改为 Optional,留空即 None;
    • 插件同步:先用邮箱定位,未提供则按 Cookie 会话 st 反查,仍未命中则生成与 add_token 一致的占位邮箱 account-<cookie_hash>@flow.local;
    • 不再因为空账号而 422。

测试

新增 tests/test_flow_cookie_snapshot_compat.py:

  • 缺失方法 → 降级返回原始串
  • 方法存在 → 正常调用
  • 方法抛异常 → 降级
  • None 输入 → 空串
python -m pytest tests/test_flow_cookie_snapshot_compat.py -q

问题
----
添加 Google Cookie 时报错:
  添加失败: Google Cookie 验证失败:
  'FlowClient' object has no attribute 'get_updated_flow_cookies'

成因
----
828b620 把 Cookie 轮换快照方法放进了 FlowFrontendMixin
(flow_frontend.py)。当部署方用自定义/旧版 flow_frontend.py 整文件覆盖时,
flow_client.py / flow_current.py 里的调用点就会 AttributeError,
整条添加 Cookie 流程直接失败。

修复
----
1. 调用点改为安全取值:缺失实现时降级返回原始 Cookie 串,
   不改变上游 Cookie 轮换快照的行为(有实现时照旧调用)。
2. _update_flow_cookie_jar 同样做存在性判断,避免流式中断。
3. Google 账号(login_account) 改为可选:
   - AddTokenRequest / PluginTokenUpdateRequest 允许留空;
   - 插件同步先用邮箱定位,未提供则按 Cookie 会话(st)反查,
     仍未命中则生成与 add_token 一致的占位邮箱
     (account-<cookie_hash>@flow.local)。

测试
----
新增 tests/test_flow_cookie_snapshot_compat.py 覆盖四种情况:
缺失方法 / 方法存在 / 方法抛错 / None 输入。
@genz27
genz27 merged commit 551cca5 into TheSmallHanCat:main Oct 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant