{"record":{"id":"916ff3f9ec15518e","repo":"mongodb/node-mongodb-native","slug":"either-a-environment-oidc-callback-or-oidc-human","errorCode":null,"errorMessage":"Either a ENVIRONMENT, OIDC_CALLBACK, or OIDC_HUMAN_CALLBACK must be specified for mechanism '${this.mechanism}'.","messagePattern":"Either a ENVIRONMENT, OIDC_CALLBACK, or OIDC_HUMAN_CALLBACK must be specified for mechanism '(.+?)'\\.","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/cmap/auth/mongo_credentials.ts","lineNumber":232,"sourceCode":"      }\n\n      if (\n        this.mechanismProperties.ENVIRONMENT &&\n        !ALLOWED_ENVIRONMENT_NAMES.includes(this.mechanismProperties.ENVIRONMENT)\n      ) {\n        throw new MongoInvalidArgumentError(\n          `Currently only a ENVIRONMENT in ${ALLOWED_ENVIRONMENT_NAMES.join(\n            ','\n          )} is supported for mechanism '${this.mechanism}'.`\n        );\n      }\n\n      if (\n        !this.mechanismProperties.ENVIRONMENT &&\n        !this.mechanismProperties.OIDC_CALLBACK &&\n        !this.mechanismProperties.OIDC_HUMAN_CALLBACK\n      ) {\n        throw new MongoInvalidArgumentError(\n          `Either a ENVIRONMENT, OIDC_CALLBACK, or OIDC_HUMAN_CALLBACK must be specified for mechanism '${this.mechanism}'.`\n        );\n      }\n\n      if (this.mechanismProperties.ALLOWED_HOSTS) {\n        const hosts = this.mechanismProperties.ALLOWED_HOSTS;\n        if (!Array.isArray(hosts)) {\n          throw new MongoInvalidArgumentError(ALLOWED_HOSTS_ERROR);\n        }\n        for (const host of hosts) {\n          if (typeof host !== 'string') {\n            throw new MongoInvalidArgumentError(ALLOWED_HOSTS_ERROR);\n          }\n        }\n      }\n    }\n\n    if (AUTH_MECHS_AUTH_SRC_EXTERNAL.has(this.mechanism)) {","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/auth/mongo_credentials.ts#L214-L250","documentation":"Thrown by MongoCredentials.validate() when MONGODB-OIDC is selected but none of ENVIRONMENT, OIDC_CALLBACK, or OIDC_HUMAN_CALLBACK are provided. OIDC requires either a built-in machine environment or an explicit callback that returns the access token; with neither, authentication cannot proceed.","triggerScenarios":"Selecting authMechanism='MONGODB-OIDC' with empty or absent mechanismProperties. Triggered during validate() on the first connection/auth attempt.","commonSituations":"Setting the mechanism name but forgetting to supply mechanismProperties. Migrating from a different mechanism and dropping the properties object. Misunderstanding that OIDC needs a callback or environment by design.","solutions":["Provide an ENVIRONMENT ('test'/'azure'/'gcp'/'k8s') for a built-in machine workflow.","Or supply OIDC_CALLBACK (machine/automated) or OIDC_HUMAN_CALLBACK (interactive) pointing at a function that returns an OIDCResponse.","Double-check the mechanismProperties object is actually passed through (URI uses authMechanismProperties=ENVIRONMENT:azure)."],"exampleFix":"// before\nnew MongoClient(url, { auth: { mechanism: 'MONGODB-OIDC' } });\n// after\nnew MongoClient(url, { auth: { mechanism: 'MONGODB-OIDC', mechanismProperties: { OIDC_CALLBACK: tokenFetcher } } });","handlingStrategy":"validation","validationCode":"function assertOidcConfigured(props) {\n  if (!props?.ENVIRONMENT && !props?.OIDC_CALLBACK && !props?.OIDC_HUMAN_CALLBACK) {\n    throw new Error('MONGODB-OIDC requires ENVIRONMENT, OIDC_CALLBACK, or OIDC_HUMAN_CALLBACK.');\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a config factory that always sets at least one OIDC source.","Smoke-test connection construction in CI to catch missing properties.","Keep OIDC option assembly in a single tested module."],"tags":["authentication","oidc","configuration"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}