{"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":"validation","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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cmap/auth/mongo_credentials.ts#L202-L238","documentation":"Thrown for MONGODB-OIDC when ENVIRONMENT is set to a value not in the allowed list (test, azure, gcp, k8s). The driver only knows how to fetch tokens for these specific machine-identity providers; any other ENVIRONMENT value is rejected.","triggerScenarios":"In MongoCredentials.validate() when mechanismProperties.ENVIRONMENT is truthy but not in ALLOWED_ENVIRONMENT_NAMES.","commonSituations":"Typo in ENVIRONMENT (e.g. 'aws' which isn't supported via ENVIRONMENT, or 'Azure' capitalized); using an arbitrary string; copy/paste from another driver's docs that supports a different set.","solutions":["Use one of: test, azure, gcp, k8s.","For AWS or other OIDC providers, supply OIDC_CALLBACK / OIDC_HUMAN_CALLBACK instead of ENVIRONMENT.","Check for capitalization and trailing spaces in the ENVIRONMENT value."],"exampleFix":"// before\n'...&authMechanismProperties=ENVIRONMENT:aws'\n\n// after (use a callback for AWS IdP)\nconst client = new MongoClient(uri, {\n  authMechanism: 'MONGODB-OIDC',\n  authMechanismProperties: { OIDC_CALLBACK: awsCallback }\n});","handlingStrategy":"validation","validationCode":"const ALLOWED = ['test','azure','gcp','k8s'];\nfunction validateOidcEnvName(env?: string) {\n  if (env && !ALLOWED.includes(env)) throw new Error(`Unsupported ENVIRONMENT: ${env}`);\n}","typeGuard":"import { MongoInvalidArgumentError } from 'mongodb';\nfunction isUnsupportedEnvironment(e: unknown): boolean {\n  return e instanceof MongoInvalidArgumentError && /Currently only a ENVIRONMENT in/.test(e.message);\n}","tryCatchPattern":null,"preventionTips":["Use only test/azure/gcp/k8s for ENVIRONMENT.","For other IdPs (AWS, Okta), pass OIDC_CALLBACK instead."],"tags":["auth","oidc","configuration"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}