Skip to content

Commit

Permalink
♻️ Use experimental SASL::ClientAdapter
Browse files Browse the repository at this point in the history
✨ Adds `registry` option to `#authenticate`.  This allows authenticator
lookup and creation to be overridden, rather than be forced to depend on
global defaults.
  • Loading branch information
nevans committed Nov 7, 2023
1 parent f27dd4c commit d30595d
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,8 @@ def starttls(**options)
# +sasl_ir+ allows or disallows sending an "initial response" (see the
# +SASL-IR+ capability, below).
#
# Override +registry+ to use a custom SASL::Authenticators registry.
#
# All other arguments are forwarded to the registered SASL authenticator for
# the requested mechanism. <em>The documentation for each individual
# mechanism must be consulted for its specific parameters.</em>
Expand Down Expand Up @@ -1248,27 +1250,9 @@ def starttls(**options)
# Previously cached #capabilities will be cleared when this method
# completes. If the TaggedResponse to #authenticate includes updated
# capabilities, they will be cached.
def authenticate(mechanism, *creds, sasl_ir: true, **props, &callback)
mechanism = mechanism.to_s.tr("_", "-").upcase
authenticator = SASL.authenticator(mechanism, *creds, **props, &callback)
cmdargs = ["AUTHENTICATE", mechanism]
if sasl_ir && capable?("SASL-IR") && auth_capable?(mechanism) &&
authenticator.respond_to?(:initial_response?) &&
authenticator.initial_response?
response = authenticator.process(nil)
cmdargs << (response.empty? ? "=" : [response].pack("m0"))
end
result = send_command_with_continuations(*cmdargs) {|data|
challenge = data.unpack1("m")
response = authenticator.process challenge
[response].pack("m0")
}
if authenticator.respond_to?(:done?) && !authenticator.done?
logout!
raise SASL::AuthenticationIncomplete, result
end
@capabilities = capabilities_from_resp_code result
result
def authenticate(...)
sasl_adapter.authenticate(...)
.tap { @capabilities = capabilities_from_resp_code _1 }
end

# Sends a {LOGIN command [IMAP4rev1 §6.2.3]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.2.3]
Expand Down

0 comments on commit d30595d

Please sign in to comment.