Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Enable ScramSHA1 auth provider #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Cursor from './Cursor';
const Server = mongodb.Server;
const ReplSet = mongodb.ReplSet;
const MongoCR = mongodb.MongoCR;
const ScramSHA1 = mongodb.ScramSHA1;

export default class Database {
constructor(connectionString, options, collections) {
Expand Down Expand Up @@ -113,9 +114,11 @@ export default class Database {

if (config.auth) {
server.addAuthProvider('mongocr', new MongoCR());
server.addAuthProvider('ScramSHA1', new ScramSHA1());
// authenticate on connect
server.on('connect', function (server) {
server.auth('mongocr', config.dbName, config.auth.user, config.auth.password,
const providerName = options.authMechanism ? options.authMechanism : 'mongocr';
server.auth(providerName, config.dbName, config.auth.user, config.auth.password,
function (error, server) {
if (error) {
reject(error);
Expand Down