Skip to content

修复 OpenAI OAuth 刷新未补全账号信息#2881

Open
xiaoyiluck666 wants to merge 1 commit into
Wei-Shaw:mainfrom
xiaoyiluck666:fix/openai-oauth-refresh-enrichment
Open

修复 OpenAI OAuth 刷新未补全账号信息#2881
xiaoyiluck666 wants to merge 1 commit into
Wei-Shaw:mainfrom
xiaoyiluck666:fix/openai-oauth-refresh-enrichment

Conversation

@xiaoyiluck666
Copy link
Copy Markdown

修复内容

本 PR 修复 OpenAI OAuth 账号刷新时账号信息补全没有生效的问题:

  • OpenAIOAuthService 的正式启动注入 PrivacyClientFactory,确保 enrichTokenInfo 能实际调用 ChatGPT backend-api。
  • 修复无 refresh_token、仅复用现有 access_token 的刷新路径,使手动“刷新令牌”时也会执行账号信息补全。
  • accounts/check 没有返回 subscription_expires_at 时,补充调用 backend-api/subscriptions?account_id=...,从 active_until 回填 Plus 到期时间。
  • 增加相关单测,覆盖订阅到期时间提取和 access-token-only 刷新仍触发 enrichment 的路径。

问题背景

当前代码里已有 OpenAI plan / privacy / subscription enrichment 相关逻辑,但 OpenAIOAuthService 在 Wire 启动链路中是直接通过 NewOpenAIOAuthService 创建的,没有注入 PrivacyClientFactory。因此 enrichTokenInfo 会因为 privacyClientFactory == nil 直接返回。

另外,当账号没有 refresh_token 但已有 access_token 时,RefreshAccountToken 会直接复用现有 token 返回,也没有执行补全逻辑。这样会导致管理员手动点击刷新后,Plus 到期时间、训练数据共享状态等字段仍然不更新。

测试

已执行:

go test ./internal/service -run "TestFetchChatGPTSubscriptionExpiresAt|TestOpenAIOAuthService_RefreshAccountToken_NoRefreshTokenUsesExistingAccessToken|TestOpenAITokenRefresher_NeedsRefresh_SkipsAccountWithoutRefreshToken|TestOpenAITokenProvider_NoRefreshTokenExpiredAccessTokenReturnsError" -count=1

结果通过。

本地也通过真实刷新接口验证:对一个 subscription_expires_at 为空的 OpenAI OAuth Plus 账号调用 /api/v1/admin/accounts/:id/refresh 后,数据库成功写入 subscription_expires_at,并更新 privacy_mode=training_off

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@xiaoyiluck666 xiaoyiluck666 force-pushed the fix/openai-oauth-refresh-enrichment branch from f677a96 to eba2046 Compare May 29, 2026 06:04
@xiaoyiluck666
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 29, 2026
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