Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

mongodb authentication patch #6

Merged
merged 2 commits into from

2 participants

@wanbok

I just added authentication functionality please check it

Wan-bok Choi added some commits
@alexeypetrushin alexeypetrushin merged commit df6b397 into alexeypetrushin:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 17, 2012
  1. Added mongodb authentication

    Wan-bok Choi authored
  2. Fix a line for authentication

    Wan-bok Choi authored
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 2 deletions.
  1. +9 −1 lib/driver/db.coffee
  2. +9 −1 lib/driver/driver.coffee
View
10 lib/driver/db.coffee
@@ -50,4 +50,12 @@ module.exports = class Driver.Db
collection.drop (err) ->
drop err
- drop()
+ drop()
+ authenticate: (username, password, callback) ->
+ throw new Error "callback required!" unless callback
+ @nDb.authenticate username, password, (err, success) =>
+ return callback err if err
+ if success
+ callback null, @
+ else
+ callback new Error('Could not authenticate user ' + username), @
View
10 lib/driver/driver.coffee
@@ -51,6 +51,7 @@ module.exports = Driver =
# default:
# name: "default_production"
# host: "localhost"
+ # auth: "auth_id:auth_pass"
# })
#
# And now You can use database alias to get the actual database.
@@ -71,7 +72,14 @@ module.exports = Driver =
dbName = dbOptions.name || 'default'
# throw new Error "no database name for '#{dbAlias}' db alias!" unless dbName
+ dbAuth = dbOptions.auth.split(":") if dbOptions.auth?
server.db dbName, (err, db) =>
return callback err if err
@dbCache[dbAlias] = db
- callback null, db
+ if dbAuth?
+ db.authenticate dbAuth[0], dbAuth[1], (err, authenticated_db) ->
+ return callback err if err
+ throw new Error "callback required!" unless authenticated_db
+ callback null, authenticated_db
+ else
+ callback null, db
Something went wrong with that request. Please try again.