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

Internal invariant of TokenCache (token_cache.ts:41): getIdpInfo() was called while idpInfo is undefined. The human workflow checks hasIdpInfo / passes idpInfo explicitly when calling getIdpInfo, so this should be unreachable from the public API. Reaching it indicates a driver bug or direct misuse of the @internal TokenCache.

Solutions

  1. File a driver bug if reached via the public API with reproduction steps
  2. With internal APIs, check cache.hasIdpInfo before cache.getIdpInfo()
  3. Upgrade the driver to pick up any fixed regression

Example fix

// before
const idp = cache.getIdpInfo();

// after
const idp = cache.hasIdpInfo ? cache.getIdpInfo() : undefined;
Defensive patterns

Strategy: type-guard

Type guard

function getIdpInfoSafe(cache: TokenCache): IdPInfo | undefined {
  return cache.hasIdpInfo ? cache.getIdpInfo() : undefined;
}

Prevention

When it happens

Trigger: Calling the internal TokenCache.getIdpInfo() without first checking hasIdpInfo; or a regression where a workflow reads idpInfo before it was put into the cache via cache.put(response, idpInfo).

Common situations: Forked/monkeypatched auth providers bypassing the hasIdpInfo guard. A driver regression where getIdpInfo is reached before the two-step SASL IdPInfo response is cached.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11). Data as JSON: /api/errors/2def4edc94f53eca. Report an issue: GitHub.

Appendix: 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 dce7939f86)