{"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":"validation","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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cmap/auth/mongo_credentials.ts#L214-L250","documentation":"Thrown for MONGODB-OIDC when none of ENVIRONMENT, OIDC_CALLBACK, or OIDC_HUMAN_CALLBACK is configured. OIDC needs at least one source of tokens: a managed-identity ENVIRONMENT (machine) or a callback (machine or human interactive). Without any, the driver has no way to obtain an access token.","triggerScenarios":"In MongoCredentials.validate() OIDC branch when all three of ENVIRONMENT, OIDC_CALLBACK, OIDC_HUMAN_CALLBACK are unset.","commonSituations":"Setting authMechanism=MONGODB-OIDC with no mechanism properties; migrating from a test setup that relied on ENVIRONMENT:test and forgetting to port the property; assuming OIDC defaults to some provider.","solutions":["Add ENVIRONMENT (test/azure/gcp/k8s) for machine workflows.","Provide OIDC_CALLBACK (machine) or OIDC_HUMAN_CALLBACK (interactive browser/device-code) function for custom IdPs.","Double-check the authMechanismProperties string parses correctly in the URI."],"exampleFix":"// before\n'mongodb://host/?authMechanism=MONGODB-OIDC'\n\n// after (interactive callback)\nconst client = new MongoClient(uri, {\n  authMechanism: 'MONGODB-OIDC',\n  authMechanismProperties: { OIDC_HUMAN_CALLBACK: myBrowserCallback }\n});","handlingStrategy":"validation","validationCode":"function validateOidcSource(props?: { ENVIRONMENT?: string; OIDC_CALLBACK?: unknown; OIDC_HUMAN_CALLBACK?: unknown }) {\n  if (!props?.ENVIRONMENT && !props?.OIDC_CALLBACK && !props?.OIDC_HUMAN_CALLBACK) {\n    throw new Error('OIDC requires ENVIRONMENT or a callback');\n  }\n}","typeGuard":"import { MongoInvalidArgumentError } from 'mongodb';\nfunction isOidcNoSource(e: unknown): boolean {\n  return e instanceof MongoInvalidArgumentError && /Either a ENVIRONMENT, OIDC_CALLBACK, or OIDC_HUMAN_CALLBACK/.test(e.message);\n}","tryCatchPattern":null,"preventionTips":["Always specify exactly one OIDC token source.","Build a shared helper that defaults the right source per environment."],"tags":["auth","oidc","configuration"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}