@@ -16,7 +16,6 @@ import {
16
16
MongoRuntimeError ,
17
17
needsRetryableWriteLabel
18
18
} from '../error' ;
19
- import { type MongoClientAuthProviders } from '../mongo_client_auth_providers' ;
20
19
import { HostAddress , ns , promiseWithResolvers } from '../utils' ;
21
20
import { AuthContext } from './auth/auth_provider' ;
22
21
import { AuthMechanism } from './auth/providers' ;
@@ -102,7 +101,7 @@ export async function performInitialHandshake(
102
101
const authContext = new AuthContext ( conn , credentials , options ) ;
103
102
conn . authContext = authContext ;
104
103
105
- const handshakeDoc = await prepareHandshakeDocument ( authContext , options . authProviders ) ;
104
+ const handshakeDoc = await prepareHandshakeDocument ( authContext ) ;
106
105
107
106
// @ts -expect-error: TODO(NODE-5141): The options need to be filtered properly, Connection options differ from Command options
108
107
const handshakeOptions : CommandOptions = { ...options } ;
@@ -196,8 +195,7 @@ export interface HandshakeDocument extends Document {
196
195
* This function is only exposed for testing purposes.
197
196
*/
198
197
export async function prepareHandshakeDocument (
199
- authContext : AuthContext ,
200
- authProviders : MongoClientAuthProviders
198
+ authContext : AuthContext
201
199
) : Promise < HandshakeDocument > {
202
200
const options = authContext . options ;
203
201
const compressors = options . compressors ? options . compressors : [ ] ;
@@ -219,7 +217,9 @@ export async function prepareHandshakeDocument(
219
217
if ( credentials . mechanism === AuthMechanism . MONGODB_DEFAULT && credentials . username ) {
220
218
handshakeDoc . saslSupportedMechs = `${ credentials . source } .${ credentials . username } ` ;
221
219
222
- const provider = authProviders . getOrCreateProvider ( AuthMechanism . MONGODB_SCRAM_SHA256 ) ;
220
+ const provider = authContext . options . authProviders . getOrCreateProvider (
221
+ AuthMechanism . MONGODB_SCRAM_SHA256
222
+ ) ;
223
223
if ( ! provider ) {
224
224
// This auth mechanism is always present.
225
225
throw new MongoInvalidArgumentError (
@@ -228,7 +228,7 @@ export async function prepareHandshakeDocument(
228
228
}
229
229
return provider . prepare ( handshakeDoc , authContext ) ;
230
230
}
231
- const provider = authProviders . getOrCreateProvider ( credentials . mechanism ) ;
231
+ const provider = authContext . options . authProviders . getOrCreateProvider ( credentials . mechanism ) ;
232
232
if ( ! provider ) {
233
233
throw new MongoInvalidArgumentError ( `No AuthProvider for ${ credentials . mechanism } defined.` ) ;
234
234
}
0 commit comments