@@ -13,8 +13,14 @@ import { X509 } from './cmap/auth/x509';
1313import { MongoInvalidArgumentError } from './error' ;
1414
1515/** @internal */
16- const AUTH_PROVIDERS = new Map < AuthMechanism | string , ( workflow ?: Workflow ) => AuthProvider > ( [
17- [ AuthMechanism . MONGODB_AWS , ( ) => new MongoDBAWS ( ) ] ,
16+ const AUTH_PROVIDERS = new Map <
17+ AuthMechanism | string ,
18+ ( authMechanismProperties : AuthMechanismProperties ) => AuthProvider
19+ > ( [
20+ [
21+ AuthMechanism . MONGODB_AWS ,
22+ ( { AWS_CREDENTIAL_PROVIDER } ) => new MongoDBAWS ( AWS_CREDENTIAL_PROVIDER )
23+ ] ,
1824 [
1925 AuthMechanism . MONGODB_CR ,
2026 ( ) => {
@@ -24,7 +30,7 @@ const AUTH_PROVIDERS = new Map<AuthMechanism | string, (workflow?: Workflow) =>
2430 }
2531 ] ,
2632 [ AuthMechanism . MONGODB_GSSAPI , ( ) => new GSSAPI ( ) ] ,
27- [ AuthMechanism . MONGODB_OIDC , ( workflow ?: Workflow ) => new MongoDBOIDC ( workflow ) ] ,
33+ [ AuthMechanism . MONGODB_OIDC , properties => new MongoDBOIDC ( getWorkflow ( properties ) ) ] ,
2834 [ AuthMechanism . MONGODB_PLAIN , ( ) => new Plain ( ) ] ,
2935 [ AuthMechanism . MONGODB_SCRAM_SHA1 , ( ) => new ScramSHA1 ( ) ] ,
3036 [ AuthMechanism . MONGODB_SCRAM_SHA256 , ( ) => new ScramSHA256 ( ) ] ,
@@ -62,37 +68,28 @@ export class MongoClientAuthProviders {
6268 throw new MongoInvalidArgumentError ( `authMechanism ${ name } not supported` ) ;
6369 }
6470
65- let provider ;
66- if ( name === AuthMechanism . MONGODB_OIDC ) {
67- provider = providerFunction ( this . getWorkflow ( authMechanismProperties ) ) ;
68- } else {
69- provider = providerFunction ( ) ;
70- }
71-
71+ const provider = providerFunction ( authMechanismProperties ) ;
7272 this . existingProviders . set ( name , provider ) ;
7373 return provider ;
7474 }
75+ }
7576
76- /**
77- * Gets either a device workflow or callback workflow.
78- */
79- getWorkflow ( authMechanismProperties : AuthMechanismProperties ) : Workflow {
80- if ( authMechanismProperties . OIDC_HUMAN_CALLBACK ) {
81- return new HumanCallbackWorkflow (
82- new TokenCache ( ) ,
83- authMechanismProperties . OIDC_HUMAN_CALLBACK
77+ /**
78+ * Gets either a device workflow or callback workflow.
79+ */
80+ function getWorkflow ( authMechanismProperties : AuthMechanismProperties ) : Workflow {
81+ if ( authMechanismProperties . OIDC_HUMAN_CALLBACK ) {
82+ return new HumanCallbackWorkflow ( new TokenCache ( ) , authMechanismProperties . OIDC_HUMAN_CALLBACK ) ;
83+ } else if ( authMechanismProperties . OIDC_CALLBACK ) {
84+ return new AutomatedCallbackWorkflow ( new TokenCache ( ) , authMechanismProperties . OIDC_CALLBACK ) ;
85+ } else {
86+ const environment = authMechanismProperties . ENVIRONMENT ;
87+ const workflow = OIDC_WORKFLOWS . get ( environment ) ?.( ) ;
88+ if ( ! workflow ) {
89+ throw new MongoInvalidArgumentError (
90+ `Could not load workflow for environment ${ authMechanismProperties . ENVIRONMENT } `
8491 ) ;
85- } else if ( authMechanismProperties . OIDC_CALLBACK ) {
86- return new AutomatedCallbackWorkflow ( new TokenCache ( ) , authMechanismProperties . OIDC_CALLBACK ) ;
87- } else {
88- const environment = authMechanismProperties . ENVIRONMENT ;
89- const workflow = OIDC_WORKFLOWS . get ( environment ) ?.( ) ;
90- if ( ! workflow ) {
91- throw new MongoInvalidArgumentError (
92- `Could not load workflow for environment ${ authMechanismProperties . ENVIRONMENT } `
93- ) ;
94- }
95- return workflow ;
9692 }
93+ return workflow ;
9794 }
9895}
0 commit comments