Skip to content

Commit 360f262

Browse files
committed
fix(cpa): do not fallback id_token to access_token
1 parent d49fff2 commit 360f262

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/core/upload/cpa_upload.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ def generate_token_json(account: Account) -> dict:
149149
CPA 格式的 Token 字典
150150
"""
151151
access_token = str(account.access_token or "").strip()
152-
id_token_raw = str(account.id_token or "").strip()
153-
# 兼容历史下游:部分工具只从 id_token 提取 chatgpt_account_id。
154-
# 当注册链路仅拿到 access_token 时,使用 access_token 作为兜底 id_token 供解析。
155-
id_token = id_token_raw or access_token
152+
id_token = str(account.id_token or "").strip()
156153
refresh_token = str(account.refresh_token or "").strip()
157154

158155
claims = _decode_jwt_payload_unverified(access_token) or _decode_jwt_payload_unverified(id_token)

tests/test_cpa_upload_token_json.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_generate_token_json_backfills_time_and_account_id_from_access_token():
4343
assert token_data["email"] == "ericvillegas9964@outlook.com"
4444
assert token_data["last_refresh"] == "2026-04-01T13:03:41+08:00"
4545
assert token_data["expired"] == "2026-04-11T13:03:41+08:00"
46-
assert token_data["id_token"] == account.access_token
46+
assert token_data["id_token"] == ""
4747
assert token_data["workspace_id"] == "acct_from_jwt"
4848
assert token_data["chatgpt_account_id"] == "acct_from_jwt"
4949

@@ -87,3 +87,28 @@ def test_generate_token_json_uses_metadata_expires_when_db_and_jwt_missing():
8787

8888
assert token_data["expired"] == "2026-06-30T13:03:46+08:00"
8989
assert token_data["id_token"] == ""
90+
91+
92+
def test_generate_token_json_keeps_real_id_token_and_uses_it_for_claims():
93+
payload = {
94+
"iat": 1775019821,
95+
"exp": 1775883821,
96+
"https://api.openai.com/auth": {"chatgpt_account_id": "acct_from_id_token"},
97+
}
98+
id_token = _jwt_with_payload(payload)
99+
100+
account = Account(
101+
email="idtoken@example.com",
102+
email_service="luckmail",
103+
access_token="",
104+
id_token=id_token,
105+
account_id="",
106+
last_refresh=None,
107+
expires_at=None,
108+
)
109+
110+
token_data = generate_token_json(account)
111+
112+
assert token_data["id_token"] == id_token
113+
assert token_data["account_id"] == "acct_from_id_token"
114+
assert token_data["chatgpt_account_id"] == "acct_from_id_token"

0 commit comments

Comments
 (0)