Class: Mongo::Auth::Scram Private

Inherits:
Base
  • Object
show all
Defined in:
build/ruby-driver-v2.19/lib/mongo/auth/scram.rb,
build/ruby-driver-v2.19/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

Direct Known Subclasses

Scram256

Defined Under Namespace

Classes: Conversation

Constant Summary collapse

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.

Since:

  • 2.0.0

'SCRAM-SHA-1'.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#connection, #user

Instance Method Summary collapse

Constructor Details

#initialize(user, connection, **opts) ⇒ 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.

Initializes the Scram authenticator.

Parameters:

  • user (Auth::User)

    The user to authenticate.

  • connection (Mongo::Connection)

    The connection to authenticate over.

  • opts (Hash)

    a customizable set of options

Options Hash (**opts):

  • speculative_auth_client_nonce (String | nil)

    The client nonce used in speculative auth on the specified connection that produced the specified speculative auth result.

  • speculative_auth_result (BSON::Document | nil)

    The value of speculativeAuthenticate field of hello response of the handshake on the specified connection.

Since:

  • 2.0.0



40
41
42
43
44
# File 'build/ruby-driver-v2.19/lib/mongo/auth/scram.rb', line 40

def initialize(user, connection, **opts)
  super
  @speculative_auth_client_nonce = opts[:speculative_auth_client_nonce]
  @speculative_auth_result = opts[:speculative_auth_result]
end

Instance Attribute Details

#speculative_auth_client_nonceString | nil (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 client nonce used in speculative auth on the current connection.

Returns:

  • (String | nil)

    The client nonce used in speculative auth on the current connection.

Since:

  • 2.0.0



48
49
50
# File 'build/ruby-driver-v2.19/lib/mongo/auth/scram.rb', line 48

def speculative_auth_client_nonce
  @speculative_auth_client_nonce
end

#speculative_auth_resultBSON::Document | nil (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 value of speculativeAuthenticate field of hello response of the handshake on the current connection.

Returns:

  • (BSON::Document | nil)

    The value of speculativeAuthenticate field of hello response of the handshake on the current connection.

Since:

  • 2.0.0



52
53
54
# File 'build/ruby-driver-v2.19/lib/mongo/auth/scram.rb', line 52

def speculative_auth_result
  @speculative_auth_result
end

Instance Method Details

#conversationObject

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.

Since:

  • 2.0.0



54
55
56
57
# File 'build/ruby-driver-v2.19/lib/mongo/auth/scram.rb', line 54

def conversation
  @conversation ||= self.class.const_get(:Conversation).new(
    user, connection, client_nonce: speculative_auth_client_nonce)
end

#loginBSON::Document

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 current connection.

Returns:

  • (BSON::Document)

    The document of the authentication response.

Since:

  • 2.0.0



62
63
64
65
66
67
68
69
70
# File 'build/ruby-driver-v2.19/lib/mongo/auth/scram.rb', line 62

def 
  converse_multi_step(connection, conversation,
    speculative_auth_result: speculative_auth_result,
  ).tap do
    unless conversation.server_verified?
      raise Error::MissingScramServerSignature
    end
  end
end