Skip to content

Commit 5bc8bff

Browse files
committed
📖 Update SASL mechanism parameter documentation
Harmonized the formatting and language of SASL mechanism parameters. Made a few corrections (e.g. where `PLAIN` should have been `XOAUTH2`). Added some RFC reference links. Etc.
1 parent 573b680 commit 5bc8bff

7 files changed

+96
-51
lines changed

lib/net/imap/sasl/anonymous_authenticator.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ class AnonymousAuthenticator
2929
# this, see Net::IMAP#authenticate or your client's authentication
3030
# method.
3131
#
32-
# #anonymous_message is an optional message which is sent to the server.
33-
# It may be sent as a positional argument or as a keyword argument.
32+
# ==== Parameters
33+
#
34+
# * _optional_ #anonymous_message — a message to send to the server.
3435
#
3536
# Any other keyword arguments are silently ignored.
3637
def initialize(anon_msg = nil, anonymous_message: nil, **)

lib/net/imap/sasl/digest_md5_authenticator.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,16 @@ class Net::IMAP::SASL::DigestMD5Authenticator
5353
#
5454
# * #username — Identity whose #password is used.
5555
# * #password — A password or passphrase associated with this #username.
56-
# * #authzid ― Alternate identity to act as or on behalf of. Optional.
57-
# * +warn_deprecation+ — Set to +false+ to silence the warning.
5856
#
59-
# See the documentation for each attribute for more details.
57+
#
58+
# * _optional_ #authzid ― Authorization identity to act as or on behalf of.
59+
#
60+
# When +authzid+ is not set, the server should derive the authorization
61+
# identity from the authentication identity.
62+
#
63+
# * _optional_ +warn_deprecation+ — Set to +false+ to silence the warning.
64+
#
65+
# Any other keyword arguments are silently ignored.
6066
def initialize(user = nil, pass = nil, authz = nil,
6167
username: nil, password: nil, authzid: nil,
6268
warn_deprecation: true, **)

lib/net/imap/sasl/external_authenticator.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ module SASL
1212
# established external to SASL, for example by TLS certificate or IPsec.
1313
class ExternalAuthenticator
1414

15-
# Authorization identity: an identity to act as or on behalf of.
15+
# Authorization identity: an identity to act as or on behalf of. The
16+
# identity form is application protocol specific. If not provided or
17+
# left blank, the server derives an authorization identity from the
18+
# authentication identity. The server is responsible for verifying the
19+
# client's credentials and verifying that the identity it associates
20+
# with the client's authentication identity is allowed to act as (or on
21+
# behalf of) the authorization identity.
22+
#
23+
# For example, an administrator or superuser might take on another role:
24+
#
25+
# imap.authenticate "PLAIN", "root", passwd, authzid: "user"
1626
#
17-
# If not explicitly provided, the server defaults to using the identity
18-
# that was authenticated by the external credentials.
1927
attr_reader :authzid
2028

2129
# :call-seq:
@@ -26,7 +34,9 @@ class ExternalAuthenticator
2634
# this, see Net::IMAP#authenticate or your client's authentication
2735
# method.
2836
#
29-
# #authzid is an optional identity to act as or on behalf of.
37+
# ==== Parameters
38+
#
39+
# * _optional_ #authzid ― Authorization identity to act as or on behalf of.
3040
#
3141
# Any other keyword parameters are quietly ignored.
3242
def initialize(authzid: nil, **)

lib/net/imap/sasl/oauthbearer_authenticator.rb

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,24 @@ module SASL
1414
class OAuthAuthenticator
1515
include GS2Header
1616

17-
# Authorization identity: an identity to act as or on behalf of.
17+
# Authorization identity: an identity to act as or on behalf of. The
18+
# identity form is application protocol specific. If not provided or
19+
# left blank, the server derives an authorization identity from the
20+
# authentication identity. The server is responsible for verifying the
21+
# client's credentials and verifying that the identity it associates
22+
# with the client's authentication identity is allowed to act as (or on
23+
# behalf of) the authorization identity.
24+
#
25+
# For example, an administrator or superuser might take on another role:
26+
#
27+
# imap.authenticate "PLAIN", "root", passwd, authzid: "user"
1828
#
19-
# If no explicit authorization identity is provided, it is usually
20-
# derived from the authentication identity. For the OAuth-based
21-
# mechanisms, the authentication identity is the identity established by
22-
# the OAuth credential.
2329
attr_reader :authzid
2430

25-
# Hostname to which the client connected.
31+
# Hostname to which the client connected. (optional)
2632
attr_reader :host
2733

28-
# Service port to which the client connected.
34+
# Service port to which the client connected. (optional)
2935
attr_reader :port
3036

3137
# HTTP method. (optional)
@@ -47,20 +53,22 @@ class OAuthAuthenticator
4753
# Creates an RFC7628[https://tools.ietf.org/html/rfc7628] OAuth
4854
# authenticator.
4955
#
50-
# === Options
56+
# ==== Parameters
5157
#
52-
# See child classes for required configuration parameter(s). The
53-
# following parameters are all optional, but protocols or servers may
54-
# add requirements for #authzid, #host, #port, or any other parameter.
58+
# See child classes for required parameter(s). The following parameters
59+
# are all optional, but it is worth noting that <b>application protocols
60+
# are allowed to require</b> #authzid (or other parameters, such as
61+
# #host or #port) <b>as are specific server implementations</b>.
5562
#
56-
# * #authzid ― Identity to act as or on behalf of.
57-
# * #host — Hostname to which the client connected.
58-
# * #port — Service port to which the client connected.
59-
# * #mthd — HTTP method
60-
# * #path — HTTP path data
61-
# * #post — HTTP post data
62-
# * #qs — HTTP query string
63+
# * _optional_ #authzid ― Authorization identity to act as or on behalf of.
64+
# * _optional_ #host — Hostname to which the client connected.
65+
# * _optional_ #port — Service port to which the client connected.
66+
# * _optional_ #mthd — HTTP method
67+
# * _optional_ #path — HTTP path data
68+
# * _optional_ #post — HTTP post data
69+
# * _optional_ #qs — HTTP query string
6370
#
71+
# Any other keyword parameters are quietly ignored.
6472
def initialize(authzid: nil, host: nil, port: nil,
6573
mthd: nil, path: nil, post: nil, qs: nil, **)
6674
@authzid = authzid
@@ -116,7 +124,7 @@ def authorization; raise "must be implemented by subclass" end
116124
# the bearer token.
117125
class OAuthBearerAuthenticator < OAuthAuthenticator
118126

119-
# An OAuth2 bearer token, generally the access token.
127+
# An OAuth 2.0 bearer token. See {RFC-6750}[https://www.rfc-editor.org/rfc/rfc6750]
120128
attr_reader :oauth2_token
121129

122130
# :call-seq:
@@ -127,19 +135,22 @@ class OAuthBearerAuthenticator < OAuthAuthenticator
127135
#
128136
# Called by Net::IMAP#authenticate and similar methods on other clients.
129137
#
130-
# === Options
138+
# ==== Parameters
139+
#
140+
# * #oauth2_token — An OAuth2 bearer token
131141
#
132-
# Only +oauth2_token+ is required by the mechanism, however protocols
133-
# and servers may add requirements for #authzid, #host, #port, or any
134-
# other parameter.
142+
# All other keyword parameters are passed to
143+
# {super}[rdoc-ref:OAuthAuthenticator::new] (see OAuthAuthenticator).
144+
# The most common ones are:
135145
#
136-
# * #oauth2_token — An OAuth2 bearer token or access token. *Required.*
137-
# May be provided as either regular or keyword argument.
138-
# * #authzid ― Identity to act as or on behalf of.
139-
# * #host — Hostname to which the client connected.
140-
# * #port — Service port to which the client connected.
141-
# * See OAuthAuthenticator documentation for less common parameters.
146+
# * _optional_ #authzid ― Authorization identity to act as or on behalf of.
147+
# * _optional_ #host — Hostname to which the client connected.
148+
# * _optional_ #port — Service port to which the client connected.
142149
#
150+
# Although only oauth2_token is required by this mechanism, it is worth
151+
# noting that <b><em>application protocols are allowed to
152+
# require</em></b> #authzid (<em>or other parameters, such as</em> #host
153+
# _or_ #port) <b><em>as are specific server implementations</em></b>.
143154
def initialize(oauth2_token_arg = nil, oauth2_token: nil, **args, &blk)
144155
super(**args, &blk) # handles authzid, host, port, etc
145156
oauth2_token && oauth2_token_arg and

lib/net/imap/sasl/plain_authenticator.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ class Net::IMAP::SASL::PlainAuthenticator
4747
#
4848
# Called by Net::IMAP#authenticate and similar methods on other clients.
4949
#
50-
# === Parameters
50+
# ==== Parameters
5151
#
5252
# * #username ― Identity whose +password+ is used.
5353
# * #password ― Password or passphrase associated with this username+.
54-
# * #authzid ― Alternate identity to act as or on behalf of. Optional.
5554
#
56-
# See attribute documentation for more details.
55+
# * _optional_ #authzid ― Authorization identity to act as or on behalf of.
56+
#
57+
# When +authzid+ is not set, the server should derive the authorization
58+
# identity from the authentication identity.
59+
#
60+
# Any other keyword parameters are quietly ignored.
5761
def initialize(user = nil, pass = nil,
5862
username: nil, password: nil, authzid: nil, **)
5963
[username, user].compact.count == 1 or

lib/net/imap/sasl/scram_authenticator.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ class ScramAuthenticator
7070
#
7171
# * #username ― Identity whose #password is used. Aliased as #authcid.
7272
# * #password ― Password or passphrase associated with this #username.
73-
# * #authzid ― Alternate identity to act as or on behalf of. Optional.
74-
# * #min_iterations - Overrides the default value (4096). Optional.
73+
# * _optional_ #authzid ― Alternate identity to act as or on behalf of.
74+
# * _optional_ #min_iterations - Overrides the default value (4096).
7575
#
76-
# See the documentation on the corresponding attributes for more.
76+
# Any other keyword parameters are quietly ignored.
7777
def initialize(username_arg = nil, password_arg = nil,
7878
username: nil, password: nil, authcid: nil, authzid: nil,
7979
min_iterations: 4096, # see both RFC5802 and RFC7677
@@ -96,6 +96,12 @@ def initialize(username_arg = nil, password_arg = nil,
9696
end
9797

9898
# Authentication identity: the identity that matches the #password.
99+
#
100+
# RFC-2831[https://tools.ietf.org/html/rfc2831] uses the term +username+.
101+
# "Authentication identity" is the generic term used by
102+
# RFC-4422[https://tools.ietf.org/html/rfc4422].
103+
# RFC-4616[https://tools.ietf.org/html/rfc4616] and many later RFCs abbreviate
104+
# this to +authcid+.
99105
attr_reader :username
100106
alias authcid username
101107

lib/net/imap/sasl/xoauth2_authenticator.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
# Google[https://developers.google.com/gmail/imap/xoauth2-protocol] and
77
# Microsoft[https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth].
88
#
9-
# This mechanism requires an OAuth2 +access_token+ which has been authorized
10-
# with the appropriate OAuth2 scopes to access IMAP. These scopes are not
11-
# standardized---consult each email service provider's documentation.
9+
# This mechanism requires an OAuth2 access token which has been authorized
10+
# with the appropriate OAuth2 scopes to access the user's services. Most of
11+
# these scopes are not standardized---consult each service provider's
12+
# documentation for their scopes.
1213
#
1314
# Although this mechanism was never standardized and has been obsoleted by
1415
# "+OAUTHBEARER+", it is still very widely supported.
@@ -19,12 +20,18 @@ class Net::IMAP::SASL::XOAuth2Authenticator
1920
# It is unclear from {Google's original XOAUTH2
2021
# documentation}[https://developers.google.com/gmail/imap/xoauth2-protocol],
2122
# whether "User" refers to the authentication identity (+authcid+) or the
22-
# authorization identity (+authzid+). It appears to behave as +authzid+.
23+
# authorization identity (+authzid+). The authentication identity is
24+
# established for the client by the OAuth token, so it seems that +username+
25+
# must be the authorization identity.
2326
#
2427
# {Microsoft's documentation for shared
2528
# mailboxes}[https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth#sasl-xoauth2-authentication-for-shared-mailboxes-in-office-365]
26-
# clearly indicate that the Office 365 server interprets it as the
29+
# _clearly_ indicates that the Office 365 server interprets it as the
2730
# authorization identity.
31+
#
32+
# Although they _should_ validate that the token has been authorized to access
33+
# the service for +username+, _some_ servers appear to ignore this field,
34+
# relying only the identity and scope authorized by the token.
2835
attr_reader :username
2936

3037
# An OAuth2 access token which has been authorized with the appropriate OAuth2
@@ -46,7 +53,7 @@ class Net::IMAP::SASL::XOAuth2Authenticator
4653
# * #oauth2_token --- An OAuth2.0 access token which is authorized to access
4754
# the service for #username.
4855
#
49-
# See the documentation for each attribute for more details.
56+
# Any other keyword parameters are quietly ignored.
5057
def initialize(user = nil, token = nil, username: nil, oauth2_token: nil, **)
5158
@username = username || user or
5259
raise ArgumentError, "missing username"
@@ -62,7 +69,7 @@ def initialize(user = nil, token = nil, username: nil, oauth2_token: nil, **)
6269
# :call-seq:
6370
# initial_response? -> true
6471
#
65-
# +PLAIN+ can send an initial client response.
72+
# +XOAUTH2+ can send an initial client response.
6673
def initial_response?; true end
6774

6875
# Returns the XOAUTH2 formatted response, which combines the +username+

0 commit comments

Comments
 (0)