class Mongo::Auth::Scram

Defines behavior for SCRAM authentication.

@api private

Constants

MECHANISM

The authentication mechanism string.

Attributes

speculative_auth_client_nonce[R]

@return [ String | nil ] The client nonce used in speculative auth on

the current connection.
speculative_auth_result[R]

@return [ BSON::Document | nil ] The value of speculativeAuthenticate

field of hello response of the handshake on the current connection.

Public Class Methods

new(user, connection, **opts) click to toggle source

Initializes the Scram authenticator.

@param [ Auth::User ] user The user to authenticate. @param [ Mongo::Connection ] connection The connection to authenticate over.

@option opts [ String | nil ] speculative_auth_client_nonce The client

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

@option opts [ BSON::Document | nil ] speculative_auth_result The

value of speculativeAuthenticate field of hello response of
the handshake on the specified connection.
Calls superclass method Mongo::Auth::Base::new
# 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

Public Instance Methods

conversation() click to toggle source
# 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
login() click to toggle source

Log the user in on the current connection.

@return [ BSON::Document ] The document of the authentication response.

# File lib/mongo/auth/scram.rb, line 62
def login
  converse_multi_step(connection, conversation,
    speculative_auth_result: speculative_auth_result,
  ).tap do
    unless conversation.server_verified?
      raise Error::MissingScramServerSignature
    end
  end
end