Class: Mongo::Auth::SCRAM

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

Overview

Defines behavior for SCRAM authentication.

Since:

  • 2.0.0

Defined Under Namespace

Classes: Conversation

Constant Summary collapse

SCRAM_SHA_1_MECHANISM =

The authentication mechanism string for SCRAM-SHA-1.

Since:

  • 2.6.0

'SCRAM-SHA-1'.freeze
SCRAM_SHA_256_MECHANISM =

The authentication mechanism string for SCRAM-SHA-256.

Since:

  • 2.6.0

'SCRAM-SHA-256'.freeze
MECHANISMS =

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

Instantiate a new authenticator.

Examples:

Create the authenticator.

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

Parameters:

Since:

  • 2.0.0



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

def initialize(user)
  @user = user
end

Instance Attribute Details

#userMongo::Auth::User (readonly)

Returns The user to authenticate.

Returns:

Since:

  • 2.0.0



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

def user
  @user
end

Instance Method Details

#login(connection) ⇒ Protocol::Message

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



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

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