Ability to set auth options #85

Closed
jeremyjannotta opened this Issue Oct 7, 2013 · 3 comments

Comments

Projects
None yet
4 participants
@jeremyjannotta

Would be great if we could pass in auth options to the db.authenticate method (http://mongodb.github.io/node-mongodb-native/api-generated/db.html#authenticate) in addition to the username and password options here:
https://github.com/kcbanner/connect-mongo/blob/master/lib/connect-mongo.js#L174

That way we can authenticate against a different db than the one we're using.

@frty2

This comment has been minimized.

Show comment Hide comment
@frty2

frty2 Oct 20, 2013

+1 authdb would be an awesome feature

frty2 commented Oct 20, 2013

+1 authdb would be an awesome feature

@jakeorr

This comment has been minimized.

Show comment Hide comment
@jakeorr

jakeorr Feb 13, 2014

+1 authdb is what I'm looking for right now.

I'm using an existing mongoose connection that is authenticated using the auth: { authDb: 'admin'} option. The mongoose connection works, but connect-mongo gets authentication errors from mongo. Here's what I'm seeing if it help:

First:

error: Server error
{ message: 'Error setting TTL index on collection : sessions',
  stack: 'Error: Error setting TTL index on collection : sessions\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/lib/connect-mongo.js:161:23\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1404:28\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1542:30\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:159:22\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:685:39\n    at Cursor.close (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:959:5)\n    at commandHandler (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:685:21)\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1806:9\n    at Server.Base._callHandler (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/base.js:442:41)\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:485:18' }

And then on subsequent requests:

MongoError: not authorized for query on hashstreet.sessions
    at Object.toError (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/utils.js:110:11)
    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:685:54
    at Cursor.close (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:959:5)
    at commandHandler (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:685:21)
    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1806:9
    at Server.Base._callHandler (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/base.js:442:41)
    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:485:18
    at MongoReply.parseBody (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
    at null.<anonymous> (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:443:20)
    at EventEmitter.emit (events.js:95:17)

jakeorr commented Feb 13, 2014

+1 authdb is what I'm looking for right now.

I'm using an existing mongoose connection that is authenticated using the auth: { authDb: 'admin'} option. The mongoose connection works, but connect-mongo gets authentication errors from mongo. Here's what I'm seeing if it help:

First:

error: Server error
{ message: 'Error setting TTL index on collection : sessions',
  stack: 'Error: Error setting TTL index on collection : sessions\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/lib/connect-mongo.js:161:23\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1404:28\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1542:30\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:159:22\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:685:39\n    at Cursor.close (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:959:5)\n    at commandHandler (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:685:21)\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1806:9\n    at Server.Base._callHandler (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/base.js:442:41)\n    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:485:18' }

And then on subsequent requests:

MongoError: not authorized for query on hashstreet.sessions
    at Object.toError (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/utils.js:110:11)
    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:685:54
    at Cursor.close (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:959:5)
    at commandHandler (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:685:21)
    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1806:9
    at Server.Base._callHandler (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/base.js:442:41)
    at /Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:485:18
    at MongoReply.parseBody (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
    at null.<anonymous> (/Users/jakeorr/Predicative/Code/hashstreet/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:443:20)
    at EventEmitter.emit (events.js:95:17)
@jakeorr

This comment has been minimized.

Show comment Hide comment
@jakeorr

jakeorr Feb 14, 2014

Just submitted a pull request with authdb support: kcbanner#96

jakeorr commented Feb 14, 2014

Just submitted a pull request with authdb support: kcbanner#96

jdesboeufs added a commit that referenced this issue Dec 24, 2014

Rewrite MongoStore initialization
* Re-use existing or upcoming mongoose connection
* Re-use existing or upcoming node-mongodb-native connection
* Accept full-featured MongoDB connection strings + advanced options
* Compatible with legacy config
* Replace callback by `connected` event
* Add debug

Fix #51, #58, #62, #66, #70, #85, #94, #96, #115, #117, #120
Fix #124, #128, #129, #130, #131, #133, #134

@jdesboeufs jdesboeufs closed this Dec 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment