@@ -26,7 +26,6 @@ import (
26
26
"go.mongodb.org/mongo-driver/mongo/writeconcern"
27
27
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
28
28
"go.mongodb.org/mongo-driver/x/mongo/driver"
29
- "go.mongodb.org/mongo-driver/x/mongo/driver/auth"
30
29
"go.mongodb.org/mongo-driver/x/mongo/driver/mongocrypt"
31
30
mcopts "go.mongodb.org/mongo-driver/x/mongo/driver/mongocrypt/options"
32
31
"go.mongodb.org/mongo-driver/x/mongo/driver/operation"
@@ -211,43 +210,16 @@ func NewClient(opts ...*options.ClientOptions) (*Client, error) {
211
210
clientOpt .SetMaxPoolSize (defaultMaxPoolSize )
212
211
}
213
212
214
- if clientOpt .Auth != nil {
215
- var oidcMachineCallback auth.OIDCCallback
216
- if clientOpt .Auth .OIDCMachineCallback != nil {
217
- oidcMachineCallback = func (ctx context.Context , args * driver.OIDCArgs ) (* driver.OIDCCredential , error ) {
218
- cred , err := clientOpt .Auth .OIDCMachineCallback (ctx , convertOIDCArgs (args ))
219
- return (* driver .OIDCCredential )(cred ), err
220
- }
221
- }
222
-
223
- var oidcHumanCallback auth.OIDCCallback
224
- if clientOpt .Auth .OIDCHumanCallback != nil {
225
- oidcHumanCallback = func (ctx context.Context , args * driver.OIDCArgs ) (* driver.OIDCCredential , error ) {
226
- cred , err := clientOpt .Auth .OIDCHumanCallback (ctx , convertOIDCArgs (args ))
227
- return (* driver .OIDCCredential )(cred ), err
228
- }
229
- }
230
-
231
- // Create an authenticator for the client
232
- client .authenticator , err = auth .CreateAuthenticator (clientOpt .Auth .AuthMechanism , & auth.Cred {
233
- Source : clientOpt .Auth .AuthSource ,
234
- Username : clientOpt .Auth .Username ,
235
- Password : clientOpt .Auth .Password ,
236
- PasswordSet : clientOpt .Auth .PasswordSet ,
237
- Props : clientOpt .Auth .AuthMechanismProperties ,
238
- OIDCMachineCallback : oidcMachineCallback ,
239
- OIDCHumanCallback : oidcHumanCallback ,
240
- }, clientOpt .HTTPClient )
241
- if err != nil {
242
- return nil , err
243
- }
213
+ client .authenticator , err = topology .NewAuthenticator (clientOpt .Auth , clientOpt .HTTPClient )
214
+ if err != nil {
215
+ return nil , fmt .Errorf ("error creating authenticator: %w" , err )
244
216
}
245
217
246
218
cfg , err := topology .NewConfigWithAuthenticator (clientOpt , client .clock , client .authenticator )
247
-
248
219
if err != nil {
249
220
return nil , err
250
221
}
222
+
251
223
client .serverAPI = topology .ServerAPIFromServerOptions (cfg .ServerOpts )
252
224
253
225
if client .deployment == nil {
@@ -266,19 +238,6 @@ func NewClient(opts ...*options.ClientOptions) (*Client, error) {
266
238
return client , nil
267
239
}
268
240
269
- // convertOIDCArgs converts the internal *driver.OIDCArgs into the equivalent
270
- // public type *options.OIDCArgs.
271
- func convertOIDCArgs (args * driver.OIDCArgs ) * options.OIDCArgs {
272
- if args == nil {
273
- return nil
274
- }
275
- return & options.OIDCArgs {
276
- Version : args .Version ,
277
- IDPInfo : (* options .IDPInfo )(args .IDPInfo ),
278
- RefreshToken : args .RefreshToken ,
279
- }
280
- }
281
-
282
241
// Connect initializes the Client by starting background monitoring goroutines.
283
242
// If the Client was created using the NewClient function, this method must be called before a Client can be used.
284
243
//
0 commit comments