Skip to content

Commit ca92659

Browse files
committed
♻️ Use SASL::AuthenticationExchange internally
1 parent bff7bc7 commit ca92659

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

lib/net/imap.rb

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,37 +1339,9 @@ def starttls(**options)
13391339
# Previously cached #capabilities will be cleared when this method
13401340
# completes. If the TaggedResponse to #authenticate includes updated
13411341
# capabilities, they will be cached.
1342-
def authenticate(mechanism, *creds,
1343-
sasl_ir: config.sasl_ir,
1344-
**props, &callback)
1345-
mechanism = SASL::Authenticators.normalize_name(mechanism)
1346-
authenticator = SASL.authenticator(mechanism, *creds, **props, &callback)
1347-
cmdargs = ["AUTHENTICATE", mechanism]
1348-
if sasl_ir && capable?("SASL-IR") && auth_capable?(mechanism) &&
1349-
authenticator.respond_to?(:initial_response?) &&
1350-
authenticator.initial_response?
1351-
response = authenticator.process(nil)
1352-
cmdargs << (response.empty? ? "=" : [response].pack("m0"))
1353-
end
1354-
process_error = nil
1355-
result = send_command_with_continuations(*cmdargs) {|data|
1356-
unless process_error
1357-
challenge = data.unpack1("m")
1358-
response = begin
1359-
authenticator.process challenge
1360-
rescue => ex
1361-
process_error = ex
1362-
end
1363-
end
1364-
process_error ? "*" : [response].pack("m0")
1365-
}
1366-
raise process_error if process_error
1367-
if authenticator.respond_to?(:done?) && !authenticator.done?
1368-
logout!
1369-
raise SASL::AuthenticationIncomplete, result
1370-
end
1371-
@capabilities = capabilities_from_resp_code result
1372-
result
1342+
def authenticate(*args, sasl_ir: config.sasl_ir, **props, &callback)
1343+
sasl_adapter.authenticate(*args, sasl_ir: sasl_ir, **props, &callback)
1344+
.tap { @capabilities = capabilities_from_resp_code _1 }
13731345
end
13741346

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

lib/net/imap/sasl/authentication_exchange.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module Net
44
class IMAP
55
module SASL
66

7-
# This API is *experimental*, and may change.
7+
# AuthenticationExchange is used internally by Net::IMAP#authenticate.
8+
# But the API is still *experimental*, and may change.
89
#
910
# TODO: use with more clients, to verify the API can accommodate them.
1011
# TODO: pass ClientAdapter#service to SASL.authenticator

0 commit comments

Comments
 (0)