Skip to content

Commit 3b6957d

Browse files
authored
fix(mongo_client_ops): only skip authentication if no authMechanism is specified
Fixes NODE-1840
1 parent 7664486 commit 3b6957d

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

lib/operations/mongo_client_ops.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ function connect(mongoClient, url, options, callback) {
216216
try {
217217
_finalOptions.credentials = generateCredentials(
218218
mongoClient,
219-
_finalOptions.user,
220-
_finalOptions.password,
219+
_finalOptions.auth.user,
220+
_finalOptions.auth.password,
221221
_finalOptions
222222
);
223223
} catch (err) {
@@ -579,21 +579,14 @@ function transformUrlOptions(_object) {
579579
object[camelCaseName] = object[name];
580580
}
581581
}
582-
if (_object.auth) {
583-
const auth = _object.auth;
584-
for (let i in auth) {
585-
if (auth[i]) {
586-
object[i] = auth[i];
587-
}
588-
}
589582

590-
if (auth.username) {
591-
object.auth = auth;
592-
object.user = auth.username;
583+
if (_object.auth) {
584+
object.auth = Object.assign({}, _object.auth);
585+
if (object.auth.db) {
586+
object.authSource = object.authSource || object.auth.db;
593587
}
594-
595-
if (auth.db) {
596-
object.authSource = object.authSource || auth.db;
588+
if (object.auth.username) {
589+
object.auth.user = object.auth.username;
597590
}
598591
}
599592

0 commit comments

Comments
 (0)