Skip to content

Commit 52039f7

Browse files
dCSevenFlorian Dopona
authored and
Florian Dopona
committed
Add Authentication documentation & simplify interface
1 parent fbb73ef commit 52039f7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

README.rdoc

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

2-
Em-mongo is no longer being maintained (hasn't been for some time). If you are interested in the commit bit
3-
or want to take over the full project, please let me know!
2+
Em-mongo needs collaborators to help maintaining this project. If you are interested, please let me know!
43

54
= EM-Mongo
65

@@ -122,6 +121,22 @@ In addition to calling your errback if the write fails, you can provide the usua
122121

123122
safe_insert( {:a=>"v"}, :last_error_params => { :fsync => true, :w => 5 } )
124123

124+
125+
== Authentication
126+
At the moment the mechhanisms SCRAM-SHA-1(:scram_sha1) and MONGODB-CR(:mongodb_cr) are supported.
127+
It works as follows:
128+
129+
# establish connection and get authentication db
130+
connection = EM::Mongo::Connection.new(db_server, port)
131+
auth_db = connection.db(db_name)
132+
133+
# authentication itself
134+
resp = auth_db.authenticate(user,password, :scram_sha1)
135+
resp.callback do |success|
136+
do_authenticated #auth successful
137+
end
138+
resp.errback {|err| auth_failure err} # authentication failed
139+
125140
== Documentation
126141

127142
em-mongo now has some YARD docs. These are mostly ported directly from the mongo-ruby-driver. While they have been updated to reflect em-mongo's async API, there are probably a few errors left over in the translation. Please file an issue or submit a pull request if you notice any inaccuracies.

lib/em-mongo/auth/mongodb_cr.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ def authenticate(username, password)
1212
auth_resp = @db.collection(SYSTEM_COMMAND_COLLECTION).first({'getnonce' => 1})
1313
auth_resp.callback do |res|
1414
if not res or not res['nonce']
15-
response.succeed false
15+
if res.nil? then response.fail "connection failure"
16+
else response.fail "invalid first server response: " + res.to_s
17+
end
1618
else
1719
auth = BSON::OrderedHash.new
1820
auth['authenticate'] = 1

0 commit comments

Comments
 (0)