{"id":"694bf394722d498a","repo":"mongodb/node-mongodb-native","slug":"reauthenticate-failed-due-to-no-auth-provider-for","errorCode":null,"errorMessage":"Reauthenticate failed due to no auth provider for ${credentials.mechanism}","messagePattern":"Reauthenticate failed due to no auth provider for (.+?)","errorType":"exception","errorClass":"MongoMissingCredentialsError","httpStatus":null,"severity":"error","filePath":"src/cmap/connection_pool.ts","lineNumber":542,"sourceCode":"    const authContext = connection.authContext;\n    if (!authContext) {\n      throw new MongoRuntimeError('No auth context found on connection.');\n    }\n    const credentials = authContext.credentials;\n    if (!credentials) {\n      throw new MongoMissingCredentialsError(\n        'Connection is missing credentials when asked to reauthenticate'\n      );\n    }\n\n    const resolvedCredentials = credentials.resolveAuthMechanism(connection.hello);\n    const provider = this.server.topology.client.s.authProviders.getOrCreateProvider(\n      resolvedCredentials.mechanism,\n      resolvedCredentials.mechanismProperties\n    );\n\n    if (!provider) {\n      throw new MongoMissingCredentialsError(\n        `Reauthenticate failed due to no auth provider for ${credentials.mechanism}`\n      );\n    }\n\n    await provider.reauth(authContext);\n\n    return;\n  }\n\n  /** Clear the min pool size timer */\n  private clearMinPoolSizeTimer(): void {\n    const minPoolSizeTimer = this.minPoolSizeTimer;\n    if (minPoolSizeTimer) {\n      clearTimeout(minPoolSizeTimer);\n    }\n  }\n\n  private destroyConnection(","sourceCodeStart":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cmap/connection_pool.ts#L524-L560","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install the optional native dependency for your mechanism: `npm install kerberos` for GSSAPI.","Verify the authMechanism value in the connection string is a supported, correctly-spelled mechanism.","Upgrade the driver; reauth support for newer mechanisms (OIDC, AWS) was added across versions.","If the provider truly lacks a reauth implementation, avoid mechanisms that expire during long-lived clients, or recycle the MongoClient before tokens expire."],"exampleFix":"// before - GSSAPI requested but kerberos package missing\nconst client = new MongoClient('mongodb://host/?authMechanism=GSSAPI');\n\n// after - install and depend on kerberos\n// npm install kerberos\nconst client = new MongoClient('mongodb://user%40REALM@host/?authMechanism=GSSAPI&authSource=$external');","handlingStrategy":"validation","validationCode":"// Ensure the optional native dependency for your mechanism is installed before runtime.\nconst mech = new URL(uri).searchParams.get('authMechanism')?.toUpperCase();\nif (mech === 'GSSAPI') {\n  try { require.resolve('kerberos'); } catch { throw new Error('Install kerberos: npm i kerberos'); }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await client.connect();\n} catch (err) {\n  if (err instanceof MongoMissingCredentialsError && /no auth provider/.test(err.message)) {\n    console.error('No auth provider for mechanism; install the required dependency or use a supported mechanism.');\n  }\n  throw err;\n}","preventionTips":["Install the optional native dependency matching your auth mechanism (kerberos for GSSAPI).","Spell authMechanism values correctly in the URI.","Upgrade the driver for reauth support of newer mechanisms."],"tags":["authentication","auth-mechanism","reauth","dependencies"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}