@@ -10,38 +10,68 @@ module SASL
1010 # TODO: raise an error if the command succeeds after being canceled.
1111 # TODO: use with more clients, to verify the API can accommodate them.
1212 #
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.
2319 #
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.
2524 #
26- # Or delegate creation of the authenticator to ::build:
2725 # def authenticate(...)
28- # SASL::AuthenticationExchange.build(sasl_adapter, ...)
29- # .authenticate
26+ # MyClient::SASLAdapter.new(self).authenticate(...)
3027 # end
3128 #
32- # As a convenience, ::authenticate combines ::build and #authenticate:
29+ # SASL::ClientAdapter#authenticate delegates to ::authenticate, like so:
30+ #
3331 # def authenticate(...)
32+ # sasl_adapter = MyClient::SASLAdapter.new(self)
3433 # SASL::AuthenticationExchange.authenticate(sasl_adapter, ...)
3534 # end
3635 #
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
3954 #
4055 class AuthenticationExchange
4156 # Convenience method for <tt>build(...).authenticate</tt>
57+ #
58+ # See also: SASL::ClientAdapter#authenticate
4259 def self . authenticate ( ...) build ( ...) . authenticate end
4360
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.
4575 def self . build ( client , mechanism , *args , sasl_ir : true , **kwargs , &block )
4676 authenticator = SASL . authenticator ( mechanism , *args , **kwargs , &block )
4777 new ( client , mechanism , authenticator , sasl_ir : sasl_ir )
0 commit comments