Skip to content

Commit c063ac0

Browse files
committed
♻️ Use experimental SASL::ClientAdapter
✨ Adds `registry` option to `#authenticate`. This allows authenticator lookup and creation to be overridden, rather than be forced to depend on global defaults.
1 parent b205add commit c063ac0

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

lib/net/imap.rb

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,8 @@ def starttls(**options)
12421242
# +SASL-IR+ capability, below). Defaults to the #config value for
12431243
# {sasl_ir}[rdoc-ref:Config#sasl_ir], which defaults to +true+.
12441244
#
1245+
# Override +registry+ to use a custom SASL::Authenticators registry.
1246+
#
12451247
# All other arguments are forwarded to the registered SASL authenticator for
12461248
# the requested mechanism. <em>The documentation for each individual
12471249
# mechanism must be consulted for its specific parameters.</em>
@@ -1336,29 +1338,9 @@ def starttls(**options)
13361338
# Previously cached #capabilities will be cleared when this method
13371339
# completes. If the TaggedResponse to #authenticate includes updated
13381340
# capabilities, they will be cached.
1339-
def authenticate(mechanism, *creds,
1340-
sasl_ir: config.sasl_ir,
1341-
**props, &callback)
1342-
mechanism = mechanism.to_s.tr("_", "-").upcase
1343-
authenticator = SASL.authenticator(mechanism, *creds, **props, &callback)
1344-
cmdargs = ["AUTHENTICATE", mechanism]
1345-
if sasl_ir && capable?("SASL-IR") && auth_capable?(mechanism) &&
1346-
authenticator.respond_to?(:initial_response?) &&
1347-
authenticator.initial_response?
1348-
response = authenticator.process(nil)
1349-
cmdargs << (response.empty? ? "=" : [response].pack("m0"))
1350-
end
1351-
result = send_command_with_continuations(*cmdargs) {|data|
1352-
challenge = data.unpack1("m")
1353-
response = authenticator.process challenge
1354-
[response].pack("m0")
1355-
}
1356-
if authenticator.respond_to?(:done?) && !authenticator.done?
1357-
logout!
1358-
raise SASL::AuthenticationIncomplete, result
1359-
end
1360-
@capabilities = capabilities_from_resp_code result
1361-
result
1341+
def authenticate(*args, sasl_ir: config.sasl_ir, **props, &callback)
1342+
sasl_adapter.authenticate(*args, sasl_ir: sasl_ir, **props, &callback)
1343+
.tap { @capabilities = capabilities_from_resp_code _1 }
13621344
end
13631345

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

0 commit comments

Comments
 (0)