diegosouzapw/OmniRoute · error · CodexAuthFileError

Only OAuth Codex connections support auth.json export

Error message

Only OAuth Codex connections support auth.json export

What it means

Second guard in resolveFreshCodexConnection: the connection is a Codex connection but its authType is not OAuth (e.g. API-key based). auth.json export requires OAuth tokens (id/access/refresh), so non-OAuth Codex connections are rejected.

Solutions

  1. Only export auth.json for Codex connections created via the OAuth (ChatGPT) flow
  2. Re-add the account through the OAuth flow to get an OAuth-type connection
  3. Use the connection's native credential type instead of auth.json export
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/lib/oauth/utils/codexAuthFile.ts:210 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/47e815cf979d7073. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/oauth/utils/codexAuthFile.ts:210

      refresh_token: refreshToken,
      account_id: accountId,
    },
    last_refresh: new Date().toISOString(),
  };
}

async function resolveFreshCodexConnection(connectionId: string): Promise<CodexConnectionLike> {
  const connection = (await getCachedProviderConnectionById(connectionId)) as CodexConnectionLike | null;
  if (!connection) {
    throw new CodexAuthFileError("Connection not found", 404, "not_found");
  }

  if (connection.provider !== "codex") {
    throw new CodexAuthFileError("Only Codex provider connections can export Codex auth files");
  }

  if (connection.authType !== "oauth") {
    throw new CodexAuthFileError("Only OAuth Codex connections support auth.json export");
  }

  if (!shouldRefreshCodexConnection(connection)) {
    return connection;
  }

  const refreshToken = toNonEmptyString(connection.refreshToken);
  if (!refreshToken) {
    throw new CodexAuthFileError(
      "Codex connection requires refresh but no refresh_token is available. Re-authenticate first.",
      409,
      "reauth_required"
    );
  }

  // Pass onPersist so the DB write is atomic with the network call inside the mutex.
  let persistedRefresh: any = null;
  const refreshed = await getAccessToken(

View on GitHub (pinned to a179ffed5b)