惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
量子位
V
V2EX
S
SegmentFault 最新的问题
月光博客
月光博客
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
博客园_首页
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
Y
Y Combinator Blog
The Cloudflare Blog
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
腾讯CDC
B
Blog
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor: share Codex auth identity helpers · openclaw/op...
vincentkoc · 2026-05-30 · via Recent Commits to openclaw:main

@@ -6,10 +6,13 @@ import {

66

markMigrationItemError,

77

markMigrationItemSkipped,

88

} from "openclaw/plugin-sdk/migration";

9-

import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";

109

import type { MigrationItem, MigrationProviderContext } from "openclaw/plugin-sdk/plugin-entry";

1110

import {

11+

buildOpenAICodexCredentialExtra,

1212

buildOauthProviderAuthResult,

13+

resolveOpenAICodexAccessTokenExpiry,

14+

resolveOpenAICodexAuthIdentity,

15+

resolveOpenAICodexImportProfileName,

1316

updateAuthProfileStoreWithLock,

1417

type AuthProfileStore,

1518

type OAuthCredential,

@@ -61,13 +64,6 @@ type HermesCodexAuthProfile = {

6164

sourceProfileId: string;

6265

};

636664-

type CodexIdentity = {

65-

accountId?: string;

66-

chatgptPlanType?: string;

67-

email?: string;

68-

profileName?: string;

69-

};

70-7167

function readTimestamp(value: unknown): number | undefined {

7268

if (typeof value !== "string" || !value.trim()) {

7369

return undefined;

@@ -76,66 +72,6 @@ function readTimestamp(value: unknown): number | undefined {

7672

return Number.isFinite(parsed) ? parsed : undefined;

7773

}

787479-

function decodeJwtPayload(token: string): Record<string, unknown> | undefined {

80-

const payload = token.split(".")[1];

81-

if (!payload) {

82-

return undefined;

83-

}

84-

try {

85-

const parsed = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));

86-

return isRecord(parsed) ? parsed : undefined;

87-

} catch {

88-

return undefined;

89-

}

90-

}

91-92-

function resolveCodexIdentity(access: string, accountId?: string): CodexIdentity {

93-

const payload = decodeJwtPayload(access);

94-

const auth = isRecord(payload?.["https://api.openai.com/auth"])

95-

? payload["https://api.openai.com/auth"]

96-

: {};

97-

const profile = isRecord(payload?.["https://api.openai.com/profile"])

98-

? payload["https://api.openai.com/profile"]

99-

: {};

100-

const email = readString(profile.email);

101-

const resolvedAccountId = accountId ?? readString(auth.chatgpt_account_id);

102-

const chatgptPlanType = readString(auth.chatgpt_plan_type);

103-

if (email) {

104-

return {

105-

...(resolvedAccountId ? { accountId: resolvedAccountId } : {}),

106-

...(chatgptPlanType ? { chatgptPlanType } : {}),

107-

email,

108-

profileName: email,

109-

};

110-

}

111-

const stableSubject =

112-

readString(auth.chatgpt_account_user_id) ??

113-

readString(auth.chatgpt_user_id) ??

114-

readString(auth.user_id) ??

115-

readString(payload?.sub) ??

116-

resolvedAccountId;

117-

return {

118-

...(resolvedAccountId ? { accountId: resolvedAccountId } : {}),

119-

...(chatgptPlanType ? { chatgptPlanType } : {}),

120-

...(stableSubject

121-

? { profileName: `id-${Buffer.from(stableSubject).toString("base64url")}` }

122-

: {}),

123-

};

124-

}

125-126-

function resolveAccessTokenExpiry(access: string): number | undefined {

127-

const payload = decodeJwtPayload(access);

128-

const exp = payload?.exp;

129-

if (typeof exp === "number" && Number.isFinite(exp) && exp > 0) {

130-

return Math.trunc(exp) * 1000;

131-

}

132-

if (typeof exp === "string") {

133-

const seconds = parseStrictPositiveInteger(exp);

134-

return seconds === undefined ? undefined : seconds * 1000;

135-

}

136-

return undefined;

137-

}

138-13975

function sourceCredentialFingerprint(candidate: HermesCodexAuthCandidate): string {

14076

const hash = createHash("sha256");

14177

for (const part of [

@@ -266,39 +202,24 @@ async function readOpenCodeOpenAICandidates(

266202

];

267203

}

268204269-

function credentialExtra(identity: CodexIdentity): Record<string, unknown> | undefined {

270-

const extra = {

271-

...(identity.accountId ? { accountId: identity.accountId } : {}),

272-

...(identity.chatgptPlanType ? { chatgptPlanType: identity.chatgptPlanType } : {}),

273-

};

274-

return Object.keys(extra).length > 0 ? extra : undefined;

275-

}

276-277-

function importProfileName(identity: CodexIdentity, fallback: string): string {

278-

if (identity.accountId) {

279-

return `account-${identity.accountId.replaceAll(/[^A-Za-z0-9._-]+/gu, "-")}`;

280-

}

281-

if (identity.profileName?.startsWith("id-")) {

282-

return identity.profileName;

283-

}

284-

return fallback;

285-

}

286-287205

function buildAuthResult(

288206

candidate: HermesCodexAuthCandidate,

289207

fallbackProfileName = "hermes-import",

290208

): ProviderAuthResult {

291-

const identity = resolveCodexIdentity(candidate.access, candidate.accountId);

209+

const identity = resolveOpenAICodexAuthIdentity({

210+

access: candidate.access,

211+

accountId: candidate.accountId,

212+

});

292213

return buildOauthProviderAuthResult({

293214

providerId: OPENAI_CODEX_PROVIDER_ID,

294215

defaultModel: OPENAI_CODEX_DEFAULT_MODEL,

295216

access: candidate.access,

296217

refresh: candidate.refresh,

297-

expires: resolveAccessTokenExpiry(candidate.access),

218+

expires: resolveOpenAICodexAccessTokenExpiry(candidate.access),

298219

email: identity.email,

299-

profileName: importProfileName(identity, fallbackProfileName),

220+

profileName: resolveOpenAICodexImportProfileName(identity, fallbackProfileName),

300221

displayName: HERMES_AUTH_DISPLAY_NAME,

301-

credentialExtra: credentialExtra(identity),

222+

credentialExtra: buildOpenAICodexCredentialExtra(identity),

302223

});

303224

}

304225