{"record":{"id":"b6efba8df15dc4c1","repo":"mongodb/node-mongodb-native","slug":"currently-only-a-environment-in-allowed-environm","errorCode":null,"errorMessage":"Currently only a ENVIRONMENT in ${ALLOWED_ENVIRONMENT_NAMES.join(',')} is supported for mechanism '${this.mechanism}'.","messagePattern":"Currently only a ENVIRONMENT in (.+?) is supported for mechanism '(.+?)'\\.","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/cmap/auth/mongo_credentials.ts","lineNumber":220,"sourceCode":"      if (this.username && this.password) {\n        throw new MongoInvalidArgumentError(\n          `No password is allowed in ENVIRONMENT '${this.mechanismProperties.ENVIRONMENT}' for '${this.mechanism}'.`\n        );\n      }\n\n      if (\n        (this.mechanismProperties.ENVIRONMENT === 'azure' ||\n          this.mechanismProperties.ENVIRONMENT === 'gcp') &&\n        !this.mechanismProperties.TOKEN_RESOURCE\n      ) {\n        throw new MongoInvalidArgumentError(TOKEN_RESOURCE_MISSING_ERROR);\n      }\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;","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/auth/mongo_credentials.ts#L202-L238","documentation":"Thrown by MongoCredentials.validate() when MONGODB-OIDC is configured with an ENVIRONMENT value not in the allowed set (test, azure, gcp, k8s). The driver only ships machine-workflow implementations for those environments; any other string is rejected at validation time.","triggerScenarios":"Providing authMechanismProperties={ ENVIRONMENT: '<anything-not-test/azure/gcp/k8s>' } with mechanism MONGODB-OIDC. Fires during validate() on the first auth attempt.","commonSituations":"Typos like ENVIRONMENT:'aws' (AWS is not an OIDC machine environment; use MONGODB-AWS mechanism instead). Using 'local' or 'development' expecting a built-in workflow. Case-sensitivity mistakes ('Azure' vs 'azure').","solutions":["Use one of the supported ENVIRONMENT values: 'test', 'azure', 'gcp', or 'k8s' (lowercase, exact).","If you need a custom/token-source flow, omit ENVIRONMENT and provide OIDC_CALLBACK or OIDC_HUMAN_CALLBACK instead.","For AWS authentication, switch the mechanism to MONGODB-AWS rather than MONGODB-OIDC with ENVIRONMENT:'aws'."],"exampleFix":"// before\nmechanismProperties: { ENVIRONMENT: 'aws' }\n// after (custom flow)\nmechanismProperties: { OIDC_CALLBACK: myCallback }","handlingStrategy":"type-guard","validationCode":"const ALLOWED = ['test','azure','gcp','k8s'];\nfunction isValidEnv(e) { return e == null || ALLOWED.includes(e); }","typeGuard":"function isOidcEnvironment(v): v is 'test'|'azure'|'gcp'|'k8s' {\n  return ['test','azure','gcp','k8s'].includes(v);\n}","tryCatchPattern":null,"preventionTips":["Constrain ENVIRONMENT in your config schema to the four allowed literals.","Reject unknown values at config-load time with a clear message.","Remember OIDC has no 'aws' ENVIRONMENT; use the MONGODB-AWS mechanism."],"tags":["authentication","oidc","configuration","validation"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}