Skip to content

Commit 1d74a33

Browse files
committed
🔒 Add secret alias to relevant SASL mechanisms
`secret` is similar to `username`: a convenient alias with ambiguous semantics. Adding it is reasonable, but I probably wouldn't add it only for `Net::IMAP`. However, `Net::SMTP` uses it, and probably others would find it useful too.
1 parent ca7f3c3 commit 1d74a33

7 files changed

+20
-14
lines changed

lib/net/imap/sasl/cram_md5_authenticator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
class Net::IMAP::SASL::CramMD5Authenticator
1717
def initialize(user = nil, pass = nil,
1818
authcid: nil, username: nil,
19-
password: nil,
19+
password: nil, secret: nil,
2020
warn_deprecation: true,
2121
**)
2222
if warn_deprecation
2323
warn "WARNING: CRAM-MD5 mechanism is deprecated." # TODO: recommend SCRAM
2424
end
2525
require "digest/md5"
2626
@user = authcid || username || user
27-
@password = password || pass
27+
@password = password || secret || pass
2828
@done = false
2929
end
3030

lib/net/imap/sasl/digest_md5_authenticator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ class Net::IMAP::SASL::DigestMD5Authenticator
6969
# Any other keyword arguments are silently ignored.
7070
def initialize(user = nil, pass = nil, authz = nil,
7171
username: nil, password: nil, authzid: nil,
72-
authcid: nil,
72+
authcid: nil, secret: nil,
7373
warn_deprecation: true, **)
7474
username = authcid || username || user or
7575
raise ArgumentError, "missing username (authcid)"
76-
password ||= pass or raise ArgumentError, "missing password"
76+
password ||= secret || pass or raise ArgumentError, "missing password"
7777
authzid ||= authz
7878
if warn_deprecation
7979
warn "WARNING: DIGEST-MD5 SASL mechanism was deprecated by RFC6331."

lib/net/imap/sasl/login_authenticator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class Net::IMAP::SASL::LoginAuthenticator
2525

2626
def initialize(user = nil, pass = nil,
2727
authcid: nil, username: nil,
28-
password: nil,
28+
password: nil, secret: nil,
2929
warn_deprecation: true,
3030
**)
3131
if warn_deprecation
3232
warn "WARNING: LOGIN SASL mechanism is deprecated. Use PLAIN instead."
3333
end
3434
@user = authcid || username || user
35-
@password = password || pass
35+
@password = password || secret || pass
3636
@state = STATE_USER
3737
end
3838

lib/net/imap/sasl/oauthbearer_authenticator.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class OAuthBearerAuthenticator < OAuthAuthenticator
139139

140140
# An OAuth 2.0 bearer token. See {RFC-6750}[https://www.rfc-editor.org/rfc/rfc6750]
141141
attr_reader :oauth2_token
142+
alias secret oauth2_token
142143

143144
# :call-seq:
144145
# new(oauth2_token, **options) -> authenticator
@@ -173,10 +174,12 @@ class OAuthBearerAuthenticator < OAuthAuthenticator
173174
# noting that <b><em>application protocols are allowed to
174175
# require</em></b> #authzid (<em>or other parameters, such as</em> #host
175176
# _or_ #port) <b><em>as are specific server implementations</em></b>.
176-
def initialize(arg1 = nil, arg2 = nil, oauth2_token: nil, **args, &blk)
177+
def initialize(arg1 = nil, arg2 = nil,
178+
oauth2_token: nil, secret: nil,
179+
**args, &blk)
177180
username, oauth2_token_arg = arg2.nil? ? [nil, arg1] : [arg1, arg2]
178181
super(username: username, **args, &blk)
179-
@oauth2_token = oauth2_token || oauth2_token_arg or
182+
@oauth2_token = oauth2_token || secret || oauth2_token_arg or
180183
raise ArgumentError, "missing oauth2_token"
181184
end
182185

lib/net/imap/sasl/plain_authenticator.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Net::IMAP::SASL::PlainAuthenticator
2626

2727
# A password or passphrase that matches the #username.
2828
attr_reader :password
29+
alias secret password
2930

3031
# Authorization identity: an identity to act as or on behalf of. The identity
3132
# form is application protocol specific. If not provided or left blank, the
@@ -64,11 +65,11 @@ class Net::IMAP::SASL::PlainAuthenticator
6465
#
6566
# Any other keyword parameters are quietly ignored.
6667
def initialize(user = nil, pass = nil,
67-
authcid: nil,
68+
authcid: nil, secret: nil,
6869
username: nil, password: nil, authzid: nil, **)
6970
username ||= authcid || user or
7071
raise ArgumentError, "missing username (authcid)"
71-
password ||= pass or raise ArgumentError, "missing password"
72+
password ||= secret || pass or raise ArgumentError, "missing password"
7273
raise ArgumentError, "username contains NULL" if username.include?(NULL)
7374
raise ArgumentError, "password contains NULL" if password.include?(NULL)
7475
raise ArgumentError, "authzid contains NULL" if authzid&.include?(NULL)

lib/net/imap/sasl/scram_authenticator.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ class ScramAuthenticator
8080
def initialize(username_arg = nil, password_arg = nil,
8181
authcid: nil, username: nil,
8282
authzid: nil,
83-
password: nil,
83+
password: nil, secret: nil,
8484
min_iterations: 4096, # see both RFC5802 and RFC7677
8585
cnonce: nil, # must only be set in tests
8686
**options)
8787
@username = username || username_arg || authcid or
8888
raise ArgumentError, "missing username (authcid)"
89-
@password = password || password_arg or
89+
@password = password || secret || password_arg or
9090
raise ArgumentError, "missing password"
9191
@authzid = authzid
9292

@@ -109,6 +109,7 @@ def initialize(username_arg = nil, password_arg = nil,
109109

110110
# A password or passphrase that matches the #username.
111111
attr_reader :password
112+
alias secret password
112113

113114
# Authorization identity: an identity to act as or on behalf of. The
114115
# identity form is application protocol specific. If not provided or

lib/net/imap/sasl/xoauth2_authenticator.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Net::IMAP::SASL::XOAuth2Authenticator
4242
# An OAuth2 access token which has been authorized with the appropriate OAuth2
4343
# scopes to use the service for #username.
4444
attr_reader :oauth2_token
45+
alias secret oauth2_token
4546

4647
# :call-seq:
4748
# new(username, oauth2_token, **) -> authenticator
@@ -68,10 +69,10 @@ class Net::IMAP::SASL::XOAuth2Authenticator
6869
#
6970
# Any other keyword parameters are quietly ignored.
7071
def initialize(user = nil, token = nil, username: nil, oauth2_token: nil,
71-
authzid: nil, **)
72+
authzid: nil, secret: nil, **)
7273
@username = authzid || username || user or
7374
raise ArgumentError, "missing username (authzid)"
74-
@oauth2_token = oauth2_token || token or
75+
@oauth2_token = oauth2_token || secret || token or
7576
raise ArgumentError, "missing oauth2_token"
7677
@done = false
7778
end

0 commit comments

Comments
 (0)