Sha256: 5eb01f38ba05569ff3e075116adb5bcbbe28a6c39d1c90d1e9e0aaa98e4f523b

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

# Registry for SASL authenticators used by Net::IMAP.
module Net::IMAP::Authenticators

  # Adds an authenticator for use with Net::IMAP#authenticate.  +auth_type+ is the
  # {SASL mechanism}[https://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml]
  # supported by +authenticator+ (for instance, "+PLAIN+").  The +authenticator+
  # is an object which defines a +#process+ method to handle authentication with
  # the server.  See Net::IMAP::PlainAuthenticator, Net::IMAP::LoginAuthenticator,
  # Net::IMAP::CramMD5Authenticator, and Net::IMAP::DigestMD5Authenticator for
  # examples.
  #
  # If +auth_type+ refers to an existing authenticator, it will be
  # replaced by the new one.
  def add_authenticator(auth_type, authenticator)
    authenticators[auth_type] = authenticator
  end

  # Builds an authenticator for Net::IMAP#authenticate.  +args+ will be passed
  # directly to the chosen authenticator's +#initialize+.
  def authenticator(mechanism, *authargs, **properties, &callback)
    authenticator = authenticators.fetch(mechanism.upcase) do
      raise ArgumentError, 'unknown auth type - "%s"' % mechanism
    end
    if authenticator.respond_to?(:new)
      authenticator.new(*authargs, **properties, &callback)
    else
      authenticator.call(*authargs, **properties, &callback)
    end
  end

  private

  def authenticators
    @authenticators ||= {}
  end

end

Net::IMAP.extend Net::IMAP::Authenticators

require_relative "authenticators/plain"

require_relative "authenticators/login"
require_relative "authenticators/cram_md5"
require_relative "authenticators/digest_md5"
require_relative "authenticators/xoauth2"

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
net-imap-0.3.3 lib/net/imap/authenticators.rb
net-imap-0.3.2 lib/net/imap/authenticators.rb
net-imap-0.3.1 lib/net/imap/authenticators.rb