@@ -13,8 +13,14 @@ import { X509 } from './cmap/auth/x509';
13
13
import { MongoInvalidArgumentError } from './error' ;
14
14
15
15
/** @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
+ ] ,
18
24
[
19
25
AuthMechanism . MONGODB_CR ,
20
26
( ) => {
@@ -24,7 +30,7 @@ const AUTH_PROVIDERS = new Map<AuthMechanism | string, (workflow?: Workflow) =>
24
30
}
25
31
] ,
26
32
[ AuthMechanism . MONGODB_GSSAPI , ( ) => new GSSAPI ( ) ] ,
27
- [ AuthMechanism . MONGODB_OIDC , ( workflow ?: Workflow ) => new MongoDBOIDC ( workflow ) ] ,
33
+ [ AuthMechanism . MONGODB_OIDC , properties => new MongoDBOIDC ( getWorkflow ( properties ) ) ] ,
28
34
[ AuthMechanism . MONGODB_PLAIN , ( ) => new Plain ( ) ] ,
29
35
[ AuthMechanism . MONGODB_SCRAM_SHA1 , ( ) => new ScramSHA1 ( ) ] ,
30
36
[ AuthMechanism . MONGODB_SCRAM_SHA256 , ( ) => new ScramSHA256 ( ) ] ,
@@ -62,37 +68,28 @@ export class MongoClientAuthProviders {
62
68
throw new MongoInvalidArgumentError ( `authMechanism ${ name } not supported` ) ;
63
69
}
64
70
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 ) ;
72
72
this . existingProviders . set ( name , provider ) ;
73
73
return provider ;
74
74
}
75
+ }
75
76
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 } `
84
91
) ;
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 ;
96
92
}
93
+ return workflow ;
97
94
}
98
95
}
0 commit comments