mongodb/node-mongodb-native · error · MongoMissingCredentialsError

Reauthenticate failed due to no auth provider for ${credenti

Error message

Reauthenticate failed due to no auth provider for ${credentials.mechanism}

What it means

Thrown by reauthenticate() when credentials exist but no auth provider is registered for the credentials' mechanism. The driver's authProviders registry maps mechanism names (e.g. 'MONGODB-AWS', 'MONGODB-OIDC', 'GSSAPI') to provider implementations; if getOrCreateProvider returns nothing for the mechanism, reauth cannot proceed. Surfaced as MongoMissingCredentialsError. It means the mechanism in use has no reauth implementation or the provider failed to initialize (often an optional native dependency missing).

Source

Thrown at src/cmap/connection_pool.ts:542

    const authContext = connection.authContext;
    if (!authContext) {
      throw new MongoRuntimeError('No auth context found on connection.');
    }
    const credentials = authContext.credentials;
    if (!credentials) {
      throw new MongoMissingCredentialsError(
        'Connection is missing credentials when asked to reauthenticate'
      );
    }

    const resolvedCredentials = credentials.resolveAuthMechanism(connection.hello);
    const provider = this.server.topology.client.s.authProviders.getOrCreateProvider(
      resolvedCredentials.mechanism,
      resolvedCredentials.mechanismProperties
    );

    if (!provider) {
      throw new MongoMissingCredentialsError(
        `Reauthenticate failed due to no auth provider for ${credentials.mechanism}`
      );
    }

    await provider.reauth(authContext);

    return;
  }

  /** Clear the min pool size timer */
  private clearMinPoolSizeTimer(): void {
    const minPoolSizeTimer = this.minPoolSizeTimer;
    if (minPoolSizeTimer) {
      clearTimeout(minPoolSizeTimer);
    }
  }

  private destroyConnection(

View on GitHub (pinned to 3366c21a63)

Solutions

  1. Install the optional native dependency for your mechanism: `npm install kerberos` for GSSAPI.
  2. Verify the authMechanism value in the connection string is a supported, correctly-spelled mechanism.
  3. Upgrade the driver; reauth support for newer mechanisms (OIDC, AWS) was added across versions.
  4. If the provider truly lacks a reauth implementation, avoid mechanisms that expire during long-lived clients, or recycle the MongoClient before tokens expire.

Example fix

// before - GSSAPI requested but kerberos package missing
const client = new MongoClient('mongodb://host/?authMechanism=GSSAPI');

// after - install and depend on kerberos
// npm install kerberos
const client = new MongoClient('mongodb://user%40REALM@host/?authMechanism=GSSAPI&authSource=$external');
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the optional native dependency for your mechanism is installed before runtime.
const mech = new URL(uri).searchParams.get('authMechanism')?.toUpperCase();
if (mech === 'GSSAPI') {
  try { require.resolve('kerberos'); } catch { throw new Error('Install kerberos: npm i kerberos'); }
}

Try / catch

try {
  await client.connect();
} catch (err) {
  if (err instanceof MongoMissingCredentialsError && /no auth provider/.test(err.message)) {
    console.error('No auth provider for mechanism; install the required dependency or use a supported mechanism.');
  }
  throw err;
}

Prevention

When it happens

Trigger: reauthenticate() resolves credentials and calls authProviders.getOrCreateProvider(mechanism, mechanismProperties); the provider is absent (e.g. the optional `kerberos` package for GSSAPI or `mongodb-client-encryption`-related provider is not installed, or the mechanism string is unrecognized). Encountered when the server requests reauth for a mechanism whose provider could not be constructed at client startup.

Common situations: Using GSSAPI/Kerberos without the `kerberos` npm package installed, or MONGODB-OIDC/AWS where the provider construction failed silently and the server later forces reauth. Custom or typo'd authMechanism strings. Driver version that does not yet support reauth for a newer mechanism.

Related errors


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