Class: Mongo::Auth::SCRAM Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/auth/scram.rb,
lib/mongo/auth/scram/conversation.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defines behavior for SCRAM authentication.

Since:

  • 2.0.0

Defined Under Namespace

Classes: Conversation

Constant Summary collapse

SCRAM_SHA_1_MECHANISM =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The authentication mechanism string for SCRAM-SHA-1.

Since:

  • 2.6.0

'SCRAM-SHA-1'.freeze
SCRAM_SHA_256_MECHANISM =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The authentication mechanism string for SCRAM-SHA-256.

Since:

  • 2.6.0

'SCRAM-SHA-256'.freeze
MECHANISMS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Map the user-specified authentication mechanism to the proper names of the mechanisms.

Since:

  • 2.6.0

{
  scram: SCRAM_SHA_1_MECHANISM,
  scram256: SCRAM_SHA_256_MECHANISM
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ SCRAM

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Instantiate a new authenticator.

Examples:

Create the authenticator.

Mongo::Auth::SCRAM.new(user)

Parameters:

Since:

  • 2.0.0



55
56
57
# File 'lib/mongo/auth/scram.rb', line 55

def initialize(user)
  @user = user
end

Instance Attribute Details

#userMongo::Auth::User (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The user to authenticate.

Returns:

Since:

  • 2.0.0



45
46
47
# File 'lib/mongo/auth/scram.rb', line 45

def user
  @user
end

Instance Method Details

#login(connection) ⇒ Protocol::Message

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Log the user in on the given connection.

Examples:

Log the user in.

user.(connection)

Parameters:

  • connection (Mongo::Connection)

    The connection to log into.

Returns:

Since:

  • 2.0.0



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/mongo/auth/scram.rb', line 69

def (connection)
  mechanism = user.mechanism || :scram
  conversation = Conversation.new(user, 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