Class: Mongo::Auth::SCRAM
- Inherits:
-
Object
- Object
- Mongo::Auth::SCRAM
- Defined in:
- lib/mongo/auth/scram.rb,
lib/mongo/auth/scram/conversation.rb
Overview
Defines behaviour for SCRAM authentication.
Defined Under Namespace
Classes: Conversation
Constant Summary collapse
- SCRAM_SHA_1_MECHANISM =
The authentication mechanism string for SCRAM-SHA-1.
'SCRAM-SHA-1'.freeze
- SCRAM_SHA_256_MECHANISM =
The authentication mechanism string for SCRAM-SHA-256.
'SCRAM-SHA-256'.freeze
- MECHANISMS =
Map the user-specified authentication mechanism to the proper names of the mechanisms.
{ scram: SCRAM_SHA_1_MECHANISM, scram256: SCRAM_SHA_256_MECHANISM }.freeze
Instance Attribute Summary collapse
-
#user ⇒ Mongo::Auth::User
readonly
The user to authenticate.
Instance Method Summary collapse
-
#initialize(user) ⇒ SCRAM
constructor
Instantiate a new authenticator.
-
#login(connection, mechanism = nil) ⇒ Protocol::Message
Log the user in on the given connection.
Constructor Details
#initialize(user) ⇒ SCRAM
Instantiate a new authenticator.
55 56 57 |
# File 'lib/mongo/auth/scram.rb', line 55 def initialize(user) @user = user end |
Instance Attribute Details
#user ⇒ Mongo::Auth::User (readonly)
Returns The user to authenticate.
45 46 47 |
# File 'lib/mongo/auth/scram.rb', line 45 def user @user end |
Instance Method Details
#login(connection, mechanism = nil) ⇒ Protocol::Message
Log the user in on the given connection.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mongo/auth/scram.rb', line 72 def login(connection, mechanism = nil) mechanism ||= user.mechanism || :scram conversation = Conversation.new(user, MECHANISMS[mechanism]) reply = connection.dispatch([ conversation.start(connection) ]) connection.update_cluster_time(Operation::Result.new(reply)) reply = connection.dispatch([ conversation.continue(reply, connection) ]) connection.update_cluster_time(Operation::Result.new(reply)) until reply.documents[0][Conversation::DONE] reply = connection.dispatch([ conversation.finalize(reply, connection) ]) connection.update_cluster_time(Operation::Result.new(reply)) end reply end |