Module: Net::IMAP::Authenticators
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Extended In:
| |
Defined in: | lib/net/imap/authenticators.rb |
Overview
Registry for SASL
authenticators used by ::Net::IMAP
.
Instance Method Summary
-
#add_authenticator(auth_type, authenticator)
Adds an authenticator for #authenticate to use.
-
#authenticator(mechanism, ...) ⇒ authenticator
Builds a new authentication session context for
mechanism
. - #authenticators private
Instance Method Details
#add_authenticator(auth_type, authenticator)
Adds an authenticator for Net::IMAP#authenticate to use. mechanism
is the {Net::IMAP::SASL mechanism} implemented by #authenticator (for instance, "PLAIN"
).
The #authenticator must respond to #new
(or #call
), receiving the authenticator configuration and return a configured authentication session. The authenticator session must respond to #process
, receiving the server’s challenge and returning the client’s response.
See PlainAuthenticator, XOauth2Authenticator
, and DigestMD5Authenticator
for examples.
# File 'lib/net/imap/authenticators.rb', line 17
def add_authenticator(auth_type, authenticator) authenticators[auth_type] = authenticator end
#authenticator(mechanism, ...) ⇒ authenticator
#authenticator(mech, *creds, **props) {|prop, auth| ... } ⇒ authenticator
#authenticator(mechanism, authnid, creds, authzid = nil) ⇒ authenticator
#authenticator(mechanism, **properties) ⇒ authenticator
#authenticator(mechanism) {|propname, authctx| ... } ⇒ authenticator
Builds a new authentication session context for mechanism
.
- Note
-
This method is intended for internal use by connection protocol code only. Protocol client users should see refer to their client’s documentation, e.g. Net::IMAP#authenticate for Net::IMAP.
The call signatures documented for this method are recommendations for authenticator implementors. All arguments (other than mechanism
) are forwarded to the registered authenticator’s #new
(or #call
) method, and each authenticator must document its own arguments.
The returned object represents a single authentication exchange and must not be reused for multiple authentication attempts.
# File 'lib/net/imap/authenticators.rb', line 42
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
#authenticators (private)
[ GitHub ]# File 'lib/net/imap/authenticators.rb', line 55
def authenticators @authenticators ||= {} end