mongodb/node-mongodb-native · error · MongoInvalidArgumentError

authMechanism ${name} not supported

Error message

authMechanism ${name} not supported

What it means

Thrown by AuthProviderManager.getOrCreateProvider when the requested SASL/auth mechanism name is not registered in the AUTH_PROVIDERS map. Supported mechanisms include SCRAM-SHA-1, SCRAM-SHA-256, MONGODB-X509, MONGODB-AWS, MONGODB-OIDC, GSSAPI (Kerberos), and PLAIN. Any other value (including typos and case variants the map does not recognize) yields this MongoInvalidArgumentError during connection.

Source

Thrown at src/mongo_client_auth_providers.ts:60

   * We don't want to create all providers at once, as some providers may not be used.
   * @param name - The name of the provider to get or create.
   * @param credentials - The credentials.
   * @returns The provider.
   * @throws MongoInvalidArgumentError if the mechanism is not supported.
   * @internal
   */
  getOrCreateProvider(
    name: AuthMechanism | string,
    authMechanismProperties: AuthMechanismProperties
  ): AuthProvider {
    const authProvider = this.existingProviders.get(name);
    if (authProvider) {
      return authProvider;
    }

    const providerFunction = AUTH_PROVIDERS.get(name);
    if (!providerFunction) {
      throw new MongoInvalidArgumentError(`authMechanism ${name} not supported`);
    }

    const provider = providerFunction(authMechanismProperties);
    this.existingProviders.set(name, provider);
    return provider;
  }
}

/**
 * Gets either a device workflow or callback workflow.
 */
function getWorkflow(authMechanismProperties: AuthMechanismProperties): Workflow {
  if (authMechanismProperties.OIDC_HUMAN_CALLBACK) {
    return new HumanCallbackWorkflow(new TokenCache(), authMechanismProperties.OIDC_HUMAN_CALLBACK);
  } else if (authMechanismProperties.OIDC_CALLBACK) {
    return new AutomatedCallbackWorkflow(new TokenCache(), authMechanismProperties.OIDC_CALLBACK);
  } else {
    const environment = authMechanismProperties.ENVIRONMENT;

View on GitHub (pinned to 3366c21a63)

Solutions

  1. Correct the authMechanism value to one of: SCRAM-SHA-1, SCRAM-SHA-256, MONGODB-X509, MONGODB-AWS, MONGODB-OIDC, GSSAPI, PLAIN.
  2. Install required optional packages: npm i kerberos for GSSAPI, ensure aws4 is present for MONGODB-AWS.
  3. Double-check spelling and casing exactly as listed (use hyphens, not underscores).

Example fix

// before
const uri = 'mongodb://u:p@h:27017/?authMechanism=SCRAMSHA256';

// after
const uri = 'mongodb://u:p@h:27017/?authMechanism=SCRAM-SHA-256';
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = new Set(['SCRAM-SHA-1','SCRAM-SHA-256','MONGODB-X509','MONGODB-AWS','MONGODB-OIDC','GSSAPI','PLAIN']);
if (!SUPPORTED.has(mechanism)) throw new Error('Unsupported authMechanism');

Type guard

function isSupportedMechanism(m): boolean {
  return ['SCRAM-SHA-1','SCRAM-SHA-256','MONGODB-X509','MONGODB-AWS','MONGODB-OIDC','GSSAPI','PLAIN'].includes(m);
}

Prevention

When it happens

Trigger: Setting authMechanism to an unrecognized string in the connection string or options; typos like 'SCRAMSHA256' or 'MONGODB_OIDC' (underscore vs hyphen); using a mechanism requiring an optional dependency that isn't installed (e.g. GSSAPI without kerberos, MONGODB-AWS without the aws sdk).

Common situations: Connection string copy-paste errors; switching auth mechanisms between environments; missing optional native dependencies; case-sensitivity mistakes.

Related errors


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