11import { type AuthProvider } from './cmap/auth/auth_provider' ;
2- import { type AWSCredentialProvider } from './cmap/auth/aws_temporary_credentials' ;
32import { GSSAPI } from './cmap/auth/gssapi' ;
43import { type AuthMechanismProperties } from './cmap/auth/mongo_credentials' ;
54import { MongoDBAWS } from './cmap/auth/mongodb_aws' ;
@@ -14,10 +13,13 @@ import { X509 } from './cmap/auth/x509';
1413import { MongoInvalidArgumentError } from './error' ;
1514
1615/** @internal */
17- const AUTH_PROVIDERS = new Map < AuthMechanism | string , ( param ?: any ) => AuthProvider > ( [
16+ const AUTH_PROVIDERS = new Map <
17+ AuthMechanism | string ,
18+ ( authMechanismProperties : AuthMechanismProperties ) => AuthProvider
19+ > ( [
1820 [
1921 AuthMechanism . MONGODB_AWS ,
20- ( credentialProvider ?: AWSCredentialProvider ) => new MongoDBAWS ( credentialProvider )
22+ ( { AWS_CREDENTIAL_PROVIDER } ) => new MongoDBAWS ( AWS_CREDENTIAL_PROVIDER )
2123 ] ,
2224 [
2325 AuthMechanism . MONGODB_CR ,
@@ -28,7 +30,7 @@ const AUTH_PROVIDERS = new Map<AuthMechanism | string, (param?: any) => AuthProv
2830 }
2931 ] ,
3032 [ AuthMechanism . MONGODB_GSSAPI , ( ) => new GSSAPI ( ) ] ,
31- [ AuthMechanism . MONGODB_OIDC , ( workflow ?: Workflow ) => new MongoDBOIDC ( workflow ) ] ,
33+ [ AuthMechanism . MONGODB_OIDC , properties => new MongoDBOIDC ( getWorkflow ( properties ) ) ] ,
3234 [ AuthMechanism . MONGODB_PLAIN , ( ) => new Plain ( ) ] ,
3335 [ AuthMechanism . MONGODB_SCRAM_SHA1 , ( ) => new ScramSHA1 ( ) ] ,
3436 [ AuthMechanism . MONGODB_SCRAM_SHA256 , ( ) => new ScramSHA256 ( ) ] ,
@@ -66,39 +68,28 @@ export class MongoClientAuthProviders {
6668 throw new MongoInvalidArgumentError ( `authMechanism ${ name } not supported` ) ;
6769 }
6870
69- let provider ;
70- if ( name === AuthMechanism . MONGODB_OIDC ) {
71- provider = providerFunction ( this . getWorkflow ( authMechanismProperties ) ) ;
72- } else if ( name === AuthMechanism . MONGODB_AWS ) {
73- provider = providerFunction ( authMechanismProperties . AWS_CREDENTIAL_PROVIDER ) ;
74- } else {
75- provider = providerFunction ( ) ;
76- }
77-
71+ const provider = providerFunction ( authMechanismProperties ) ;
7872 this . existingProviders . set ( name , provider ) ;
7973 return provider ;
8074 }
75+ }
8176
82- /**
83- * Gets either a device workflow or callback workflow.
84- */
85- getWorkflow ( authMechanismProperties : AuthMechanismProperties ) : Workflow {
86- if ( authMechanismProperties . OIDC_HUMAN_CALLBACK ) {
87- return new HumanCallbackWorkflow (
88- new TokenCache ( ) ,
89- 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 } `
9091 ) ;
91- } else if ( authMechanismProperties . OIDC_CALLBACK ) {
92- return new AutomatedCallbackWorkflow ( new TokenCache ( ) , authMechanismProperties . OIDC_CALLBACK ) ;
93- } else {
94- const environment = authMechanismProperties . ENVIRONMENT ;
95- const workflow = OIDC_WORKFLOWS . get ( environment ) ?.( ) ;
96- if ( ! workflow ) {
97- throw new MongoInvalidArgumentError (
98- `Could not load workflow for environment ${ authMechanismProperties . ENVIRONMENT } `
99- ) ;
100- }
101- return workflow ;
10292 }
93+ return workflow ;
10394 }
10495}
0 commit comments