@@ -10,38 +10,68 @@ module SASL
10
10
# TODO: raise an error if the command succeeds after being canceled.
11
11
# TODO: use with more clients, to verify the API can accommodate them.
12
12
#
13
- # Create an AuthenticationExchange from a client adapter and a mechanism
14
- # authenticator:
15
- # def authenticate(mechanism, ...)
16
- # authenticator = SASL.authenticator(mechanism, ...)
17
- # SASL::AuthenticationExchange.new(
18
- # sasl_adapter, mechanism, authenticator
19
- # ).authenticate
20
- # end
21
- #
22
- # private
13
+ # An AuthenticationExchange represents a single attempt to authenticate
14
+ # a SASL client to a SASL server. It is created from a client adapter, a
15
+ # mechanism name, and a mechanism authenticator. When #authenticate is
16
+ # called, it will send the appropriate authenticate command to the server,
17
+ # returning the client response on success and raising an exception on
18
+ # failure.
23
19
#
24
- # def sasl_adapter = MyClientAdapter.new(self, &method(:send_command))
20
+ # In most cases, the client will not need to use
21
+ # SASL::AuthenticationExchange directly at all. Instead, use
22
+ # SASL::ClientAdapter#authenticate. If customizations are needed, the
23
+ # custom client adapter is probably the best place for that code.
25
24
#
26
- # Or delegate creation of the authenticator to ::build:
27
25
# def authenticate(...)
28
- # SASL::AuthenticationExchange.build(sasl_adapter, ...)
29
- # .authenticate
26
+ # MyClient::SASLAdapter.new(self).authenticate(...)
30
27
# end
31
28
#
32
- # As a convenience, ::authenticate combines ::build and #authenticate:
29
+ # SASL::ClientAdapter#authenticate delegates to ::authenticate, like so:
30
+ #
33
31
# def authenticate(...)
32
+ # sasl_adapter = MyClient::SASLAdapter.new(self)
34
33
# SASL::AuthenticationExchange.authenticate(sasl_adapter, ...)
35
34
# end
36
35
#
37
- # Likewise, ClientAdapter#authenticate delegates to #authenticate:
38
- # def authenticate(...) = sasl_adapter.authenticate(...)
36
+ # ::authenticate simply delegates to ::build and #authenticate, like so:
37
+ #
38
+ # def authenticate(...)
39
+ # sasl_adapter = MyClient::SASLAdapter.new(self)
40
+ # SASL::AuthenticationExchange
41
+ # .build(sasl_adapter, ...)
42
+ # .authenticate
43
+ # end
44
+ #
45
+ # And ::build delegates to SASL.authenticator and ::new, like so:
46
+ #
47
+ # def authenticate(mechanism, ...)
48
+ # sasl_adapter = MyClient::SASLAdapter.new(self)
49
+ # authenticator = SASL.authenticator(mechanism, ...)
50
+ # SASL::AuthenticationExchange
51
+ # .new(sasl_adapter, mechanism, authenticator)
52
+ # .authenticate
53
+ # end
39
54
#
40
55
class AuthenticationExchange
41
56
# Convenience method for <tt>build(...).authenticate</tt>
57
+ #
58
+ # See also: SASL::ClientAdapter#authenticate
42
59
def self . authenticate ( ...) build ( ...) . authenticate end
43
60
44
- # Use +registry+ to override the global Authenticators registry.
61
+ # Convenience method to combine the creation of a new authenticator and
62
+ # a new Authentication exchange.
63
+ #
64
+ # +client+ must be an instance of SASL::ClientAdapter.
65
+ #
66
+ # +mechanism+ must be a SASL mechanism name, as a string or symbol.
67
+ #
68
+ # +sasl_ir+ allows or disallows sending an "initial response", depending
69
+ # also on whether the server capabilities, mechanism authenticator, and
70
+ # client adapter all support it. Defaults to +true+.
71
+ #
72
+ # +mechanism+, +args+, +kwargs+, and +block+ are all forwarded to
73
+ # SASL.authenticator. Use the +registry+ kwarg to override the global
74
+ # SASL::Authenticators registry.
45
75
def self . build ( client , mechanism , *args , sasl_ir : true , **kwargs , &block )
46
76
authenticator = SASL . authenticator ( mechanism , *args , **kwargs , &block )
47
77
new ( client , mechanism , authenticator , sasl_ir : sasl_ir )
0 commit comments