Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@anthropic-ai/sandbox-runtime": "0.0.79",
"@corbits/codex-provider": "0.1.3",
"@corbits/meta-provider": "0.1.1",
"@corbits/oauth-core": "0.3.2",
"@corbits/oauth-core": "0.3.3",
"@corbits/openai-responses": "0.2.2",
"@corbits/xai-provider": "0.1.4",
"@intx/agent": "workspace:*",
Expand Down
8 changes: 4 additions & 4 deletions src/auth/codex/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ describe("codexTokensFromResponse", () => {
expect(tokens.refresh).toBe("old-refresh");
});

test("throws when no refresh token is available anywhere", () => {
expect(() => codexTokensFromResponse({ access_token: "a" }, 0)).toThrow(
/refresh_token/,
);
test("omits refresh when no refresh token is available anywhere", () => {
const tokens = codexTokensFromResponse({ access_token: "a" }, 0);
expect(tokens.access).toBe("a");
expect(tokens.refresh).toBeUndefined();
});

test("falls back to a default lifetime when expires_in is absent", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/auth/codex/session-failure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("codex auth failure surface", () => {
const auth = failure as CodexAuthError;
const surfaced = authFailureSurface(auth);
expect(surfaced).not.toContain(refresh);
expect(surfaced).toContain("grant rejected");
expect(surfaced).toContain("OAuth token endpoint returned 400");
expect(surfaced).toContain("Re-authenticate");
} finally {
globalThis.fetch = originalFetch;
Expand Down
9 changes: 7 additions & 2 deletions src/auth/meta/session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
createTokenSession,
isTokenExpired,
OAuthMissingRefreshTokenError,
OAuthProfileNotFoundError,
OAuthRefreshFailedError,
type TokenSession,
Expand Down Expand Up @@ -145,11 +146,15 @@ export async function refreshStagedMetaTokens(
now: number = Date.now(),
): Promise<MetaOAuthTokens> {
if (!isMetaTokenExpired(tokens, now)) return tokens;
const refreshToken = tokens.refresh;
if (refreshToken === undefined || refreshToken.trim().length === 0) {
throw new OAuthMissingRefreshTokenError();
}
let refreshed: MetaOAuthTokens;
try {
refreshed = await refreshMetaTokens(tokens.refresh, now);
refreshed = await refreshMetaTokens(refreshToken, now);
} catch (error) {
throw sanitizedRefreshFailure(error, tokens.refresh);
throw sanitizedRefreshFailure(error, refreshToken);
}
replaceMutableTokens(tokens, refreshed);
return tokens;
Expand Down
9 changes: 7 additions & 2 deletions src/auth/provider-token-session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
createTokenSession,
isTokenExpired,
OAuthMissingRefreshTokenError,
OAuthProfileNotFoundError,
OAuthRefreshFailedError,
type AuthProfile,
Expand Down Expand Up @@ -195,11 +196,15 @@ export function createProviderTokenSession<TTokens extends BaseTokens, TAccess>(
},
refreshStaged: async (tokens, now = Date.now()) => {
if (!isExpired(tokens, now)) return tokens;
const refreshToken = tokens.refresh;
if (refreshToken === undefined || refreshToken.trim().length === 0) {
throw new OAuthMissingRefreshTokenError();
}
let refreshed: TTokens;
try {
refreshed = await spec.refreshTokens(tokens.refresh, now, tokens);
refreshed = await spec.refreshTokens(refreshToken, now, tokens);
} catch (error) {
throw sanitizedRefreshFailure(error, tokens.refresh);
throw sanitizedRefreshFailure(error, refreshToken);
}
replaceMutableTokens(tokens, refreshed);
return tokens;
Expand Down
2 changes: 1 addition & 1 deletion src/auth/xai/session-refresh-race.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ describe("xAI shared-credential refresh race", () => {
const auth = failure as XaiAuthError;
const surfaced = authFailureSurface(auth);
expect(surfaced).not.toContain(refresh);
expect(surfaced).toContain("grant rejected");
expect(surfaced).toContain("OAuth token endpoint returned 400");
expect(surfaced).toContain("Re-authenticate");
} finally {
globalThis.fetch = originalFetch;
Expand Down
Loading