{"id":"45ce5fed9352f246","repo":"mongodb/node-mongodb-native","slug":"authmechanism-name-not-supported","errorCode":null,"errorMessage":"authMechanism ${name} not supported","messagePattern":"authMechanism (.+?) not supported","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/mongo_client_auth_providers.ts","lineNumber":60,"sourceCode":"   * We don't want to create all providers at once, as some providers may not be used.\n   * @param name - The name of the provider to get or create.\n   * @param credentials - The credentials.\n   * @returns The provider.\n   * @throws MongoInvalidArgumentError if the mechanism is not supported.\n   * @internal\n   */\n  getOrCreateProvider(\n    name: AuthMechanism | string,\n    authMechanismProperties: AuthMechanismProperties\n  ): AuthProvider {\n    const authProvider = this.existingProviders.get(name);\n    if (authProvider) {\n      return authProvider;\n    }\n\n    const providerFunction = AUTH_PROVIDERS.get(name);\n    if (!providerFunction) {\n      throw new MongoInvalidArgumentError(`authMechanism ${name} not supported`);\n    }\n\n    const provider = providerFunction(authMechanismProperties);\n    this.existingProviders.set(name, provider);\n    return provider;\n  }\n}\n\n/**\n * Gets either a device workflow or callback workflow.\n */\nfunction getWorkflow(authMechanismProperties: AuthMechanismProperties): Workflow {\n  if (authMechanismProperties.OIDC_HUMAN_CALLBACK) {\n    return new HumanCallbackWorkflow(new TokenCache(), authMechanismProperties.OIDC_HUMAN_CALLBACK);\n  } else if (authMechanismProperties.OIDC_CALLBACK) {\n    return new AutomatedCallbackWorkflow(new TokenCache(), authMechanismProperties.OIDC_CALLBACK);\n  } else {\n    const environment = authMechanismProperties.ENVIRONMENT;","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/mongo_client_auth_providers.ts#L42-L78","documentation":"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.","triggerScenarios":"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).","commonSituations":"Connection string copy-paste errors; switching auth mechanisms between environments; missing optional native dependencies; case-sensitivity mistakes.","solutions":["Correct the authMechanism value to one of: SCRAM-SHA-1, SCRAM-SHA-256, MONGODB-X509, MONGODB-AWS, MONGODB-OIDC, GSSAPI, PLAIN.","Install required optional packages: npm i kerberos for GSSAPI, ensure aws4 is present for MONGODB-AWS.","Double-check spelling and casing exactly as listed (use hyphens, not underscores)."],"exampleFix":"// before\nconst uri = 'mongodb://u:p@h:27017/?authMechanism=SCRAMSHA256';\n\n// after\nconst uri = 'mongodb://u:p@h:27017/?authMechanism=SCRAM-SHA-256';","handlingStrategy":"validation","validationCode":"const SUPPORTED = new Set(['SCRAM-SHA-1','SCRAM-SHA-256','MONGODB-X509','MONGODB-AWS','MONGODB-OIDC','GSSAPI','PLAIN']);\nif (!SUPPORTED.has(mechanism)) throw new Error('Unsupported authMechanism');","typeGuard":"function isSupportedMechanism(m): boolean {\n  return ['SCRAM-SHA-1','SCRAM-SHA-256','MONGODB-X509','MONGODB-AWS','MONGODB-OIDC','GSSAPI','PLAIN'].includes(m);\n}","tryCatchPattern":null,"preventionTips":["Spell mechanisms exactly with hyphens","Install optional deps (kerberos, aws4) for GSSAPI/AWS","Validate the mechanism against the supported set at startup"],"tags":["auth","auth-mechanism","connection-string","configuration"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}