class Net::IMAP::SASL::Authenticators
ScramSHA1Authenticator for examples.
See the source for PlainAuthenticator, XOAuth2Authenticator, and
and an exception should be raised if the exchange terminates prematurely.
time with nil. When #done? returns false, the exchange is incomplete#initial_response? returns true, #process may be called the first
also respond to #initial_response? and #done?. When
server’s challenge and returning the client’s response. Optionally, it may
An authenticator instance object must respond to #process, receiving the
authentication attempts.
authentication exchange and must not be reused for multiple
authenticator instance. The returned object represents a single
a proc), receiving any credentials and options and returning an
Registered authenticators must respond to #new or #call (e.g. a class or
Registry for SASL authenticators
def self.normalize_name(mechanism) -(mechanism.to_s.upcase.tr(?_, ?-)) end
Normalize the mechanism name as an uppercase string, with underscores
def self.normalize_name(mechanism) -(mechanism.to_s.upcase.tr(?_, ?-)) end
def add_authenticator(name, authenticator = nil)
lazily loaded from Net::IMAP::SASL::#{name}Authenticator (case is
When only a single argument is given, the authenticator class will be
the old authenticator will be replaced.
If +mechanism+ refers to an existing authenticator,
implemented by +authenticator_class+ (for instance, "PLAIN").
{SASL mechanism}[https://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml]
name of the
Registers an authenticator for #authenticator to use. +mechanism+ is the
add_authenticator(mechanism, authenticator_proc)
add_authenticator(mechanism, authenticator_class)
add_authenticator(mechanism)
:call-seq:
def add_authenticator(name, authenticator = nil) authenticator ||= begin class_name = "#{name.gsub(/[^a-zA-Z0-9]/, "")}Authenticator".to_sym auth_class = nil ->(*creds, **props, &block) { auth_class ||= Net::IMAP::SASL.const_get(class_name) auth_class.new(*creds, **props, &block) } end key = Authenticators.normalize_name(name) @authenticators[key] = authenticator end
def authenticator(mechanism, ...)
only. Protocol client users should see refer to their client's
This method is intended for internal use by connection protocol code
[Note]
document its own arguments.
authenticator's +#new+ or +#call+ method. Each authenticator must
All arguments (except +mechanism+) are forwarded to the registered
attempts.
exchange and must not be reused for multiple authentication
+mechanism+. The returned object represents a single authentication
Builds an authenticator instance using the authenticator registered to
authenticator(mechanism, ...) -> auth_session
:call-seq:
def authenticator(mechanism, ...) key = Authenticators.normalize_name(mechanism) auth = @authenticators.fetch(key) do raise ArgumentError, 'unknown auth type - "%s"' % key end auth.respond_to?(:new) ? auth.new(...) : auth.call(...) end
def initialize(use_defaults: true, use_deprecated: true)
+use_deprecated+ is +false+, deprecated authenticators will not be
When +use_defaults+ is +false+, the registry will start empty. When
to reuse the default global registry.
This class is usually not instantiated directly. Use SASL.authenticators
Create a new Authenticators registry.
def initialize(use_defaults: true, use_deprecated: true) @authenticators = {} return unless use_defaults add_authenticator "Anonymous" add_authenticator "External" add_authenticator "OAuthBearer" add_authenticator "Plain" add_authenticator "Scram-SHA-1" add_authenticator "Scram-SHA-256" add_authenticator "XOAuth2" return unless use_deprecated add_authenticator "Login" # deprecated add_authenticator "Cram-MD5" # deprecated add_authenticator "Digest-MD5" # deprecated end
def mechanism?(name)
def mechanism?(name) key = Authenticators.normalize_name(name) @authenticators.key?(key) end
def names; @authenticators.keys end
def names; @authenticators.keys end
def remove_authenticator(name)
def remove_authenticator(name) key = Authenticators.normalize_name(name) @authenticators.delete(key) end