mongodb/node-mongodb-native · error · MongoOIDCError

Attempted to get IDP information when none exists.

Error message

Attempted to get IDP information when none exists.

What it means

Thrown by the OIDC TokenCache.getIdpInfo() when no IdP (Identity Provider) information is cached (src/cmap/auth/mongodb_oidc/token_cache.ts:40). Internal invariant: callers must check hasIdpInfo before invoking getIdpInfo. Surfaced as a MongoDriverError (local MongoOIDCError subclass), reflecting a workflow state-machine bug rather than a user configuration problem.

Source

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

  }

  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;
    }
  }

  removeAccessToken() {
    this.accessToken = undefined;
  }

  removeRefreshToken() {

View on GitHub (pinned to 3366c21a63)

Solutions

  1. Upgrade to the latest driver patch release.
  2. If reproducible, file a driver bug with the OIDC environment and steps.
  3. As a workaround, recreate the MongoClient to reset cache state.
  4. Ensure you are not using an internal/experimental OIDC API surface.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await client.connect();
} catch (e) {
  if (e instanceof MongoDriverError && /get IDP information 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: a workflow path calls cache.getIdpInfo() before the IdP info has been populated by a successful Two-Step SASL conversation. Not reachable through normal public API usage.

Common situations: Not user-triggered in normal operation. Could appear after a driver regression in the human workflow reauthenticate path.

Related errors


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