mongodb/node-mongodb-native · error · MongoOIDCError

Attempted to get a refresh token when none exists.

Error message

Attempted to get a refresh token when none exists.

What it means

Thrown by the OIDC TokenCache.getRefreshToken() when no refresh token is cached (src/cmap/auth/mongodb_oidc/token_cache.ts:33). Internal invariant: the human workflow is expected to check hasRefreshToken before calling getRefreshToken. Surfaced as a MongoDriverError (local MongoOIDCError subclass), indicating an orchestration bug rather than user misconfiguration.

Source

Thrown at src/cmap/auth/mongodb_oidc/token_cache.ts:34

  get hasRefreshToken(): boolean {
    return !!this.refreshToken;
  }

  get hasIdpInfo(): boolean {
    return !!this.idpInfo;
  }

  getAccessToken(): string {
    if (!this.accessToken) {
      throw new MongoOIDCError('Attempted to get an access token when none exists.');
    }
    return this.accessToken;
  }

  getRefreshToken(): string {
    if (!this.refreshToken) {
      throw new MongoOIDCError('Attempted to get a refresh token when none exists.');
    }
    return this.refreshToken;
  }

  getIdpInfo(): IdPInfo {
    if (!this.idpInfo) {
      throw new MongoOIDCError('Attempted to get IDP information when none exists.');
    }
    return this.idpInfo;
  }

  put(response: OIDCResponse, idpInfo?: IdPInfo) {
    this.accessToken = response.accessToken;
    this.refreshToken = response.refreshToken;
    this.expiresInSeconds = response.expiresInSeconds;
    if (idpInfo) {
      this.idpInfo = idpInfo;
    }

View on GitHub (pinned to 3366c21a63)

Solutions

  1. Upgrade to the latest driver patch release.
  2. If reproducible, file a driver bug with version and reproduction steps.
  3. As a workaround, recreate the MongoClient to reset cache state.
  4. Avoid sharing a MongoClient across processes or after an authentication failure.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await client.connect();
} catch (e) {
  if (e instanceof MongoDriverError && /get a refresh token when none exists/.test(e.message)) {
    client.close();
    throw new Error('Driver OIDC cache invariant violated - please file a bug.');
  }
  throw e;
}

Prevention

When it happens

Trigger: Internal: the human callback workflow calls cache.getRefreshToken() without first verifying cache.hasRefreshToken. Not reachable via normal public API use.

Common situations: Not user-triggered normally. Could occur after a driver regression in the OIDC reauthenticate path, or if the cache state is corrupted by concurrent reauth attempts.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04). Data as JSON: /data/errors/0255b3b73d7352a4.json. Report an issue: GitHub.