Skip to content

Commit df121ad

Browse files
committed
📚 Update SASL PLAIN docs and add attr_readers
1 parent c99081c commit df121ad

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

lib/net/imap/sasl/plain_authenticator.rb

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,55 @@
11
# frozen_string_literal: true
22

33
# Authenticator for the "+PLAIN+" SASL mechanism, specified in
4-
# RFC4616[https://tools.ietf.org/html/rfc4616]. See Net::IMAP#authenticate.
4+
# RFC-4616[https://tools.ietf.org/html/rfc4616]. See Net::IMAP#authenticate.
55
#
66
# +PLAIN+ authentication sends the password in cleartext.
7-
# RFC3501[https://tools.ietf.org/html/rfc3501] encourages servers to disable
7+
# RFC-3501[https://tools.ietf.org/html/rfc3501] encourages servers to disable
88
# cleartext authentication until after TLS has been negotiated.
9-
# RFC8314[https://tools.ietf.org/html/rfc8314] recommends TLS version 1.2 or
9+
# RFC-8314[https://tools.ietf.org/html/rfc8314] recommends TLS version 1.2 or
1010
# greater be used for all traffic, and deprecate cleartext access ASAP. +PLAIN+
1111
# can be secured by TLS encryption.
1212
class Net::IMAP::SASL::PlainAuthenticator
13+
1314
NULL = -"\0".b
1415
private_constant :NULL
1516

16-
# +username+ is the authentication identity, the identity whose +password+ is
17-
# used. +username+ is referred to as +authcid+ by
18-
# RFC4616[https://tools.ietf.org/html/rfc4616].
17+
# Authentication identity: the identity that matches the #password.
18+
#
19+
# RFC-4616[https://tools.ietf.org/html/rfc4616] and many later RFCs abbreviate
20+
# this to +authcid+.
21+
attr_reader :username
22+
23+
# A password or passphrase that matches the #username.
24+
attr_reader :password
25+
26+
# Authorization identity: an identity to act as or on behalf of. The identity
27+
# form is application protocol specific. If not provided or left blank, the
28+
# server derives an authorization identity from the authentication identity.
29+
# The server is responsible for verifying the client's credentials and
30+
# verifying that the identity it associates with the client's authentication
31+
# identity is allowed to act as (or on behalf of) the authorization identity.
1932
#
20-
# +authzid+ is the authorization identity (identity to act as). It can
21-
# usually be left blank. When +authzid+ is left blank (nil or empty string)
22-
# the server will derive an identity from the credentials and use that as the
23-
# authorization identity.
33+
# For example, an administrator or superuser might take on another role:
34+
#
35+
# imap.authenticate "PLAIN", "root", passwd, authzid: "user"
36+
#
37+
attr_reader :authzid
38+
39+
# :call-seq:
40+
# new(username, password, authzid: nil) -> authenticator
41+
#
42+
# Creates an Authenticator for the "+PLAIN+" SASL mechanism.
43+
#
44+
# Called by Net::IMAP#authenticate and similar methods on other clients.
45+
#
46+
# === Parameters
47+
#
48+
# * #username ― Identity whose +password+ is used.
49+
# * #password ― Password or passphrase associated with this username+.
50+
# * #authzid ― Alternate identity to act as or on behalf of. Optional.
51+
#
52+
# See attribute documentation for more details.
2453
def initialize(username, password, authzid: nil)
2554
raise ArgumentError, "username contains NULL" if username&.include?(NULL)
2655
raise ArgumentError, "password contains NULL" if password&.include?(NULL)
@@ -30,8 +59,13 @@ def initialize(username, password, authzid: nil)
3059
@authzid = authzid
3160
end
3261

62+
# :call-seq:
63+
# initial_response? -> true
64+
#
65+
# +PLAIN+ can send an initial client response.
3366
def initial_response?; true end
3467

68+
# Responds with the client's credentials.
3569
def process(data)
3670
return "#@authzid\0#@username\0#@password"
3771
end

0 commit comments

Comments
 (0)