Class: Mongo::Auth::Scram Private

Inherits:
Base
  • 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

API:

  • private

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

API:

  • private

'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.

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

Parameters:

  • The user to authenticate.

  • The connection to authenticate over.

  • a customizable set of options

API:

  • private



40
41
42
43
44
# File '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.

Since:

  • 2.0.0

Returns:

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

API:

  • private



48
49
50
# File '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.

Since:

  • 2.0.0

Returns:

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

API:

  • private



52
53
54
# File '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

API:

  • private



54
55
56
57
# File '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.

Since:

  • 2.0.0

Returns:

  • The document of the authentication response.

API:

  • private



62
63
64
65
66
67
68
69
70
# File '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