Skip to content

Commit f36d753

Browse files
committed
🔒 Update OAuthBearer to take one or two arguments
`OAuthBearerAuthenticator` was updated to allow two arguments, in order to match the common `auth(username, secret)` parameter style. In my opinion, this makes the API a little bit confusing. But the mechanism only requires one argument, so it's natural to allow a single argument version. And this two argument version matches with how many clients and applications seem to_assume_ the SASL mechanisms _always_ work.
1 parent 5f9027e commit f36d753

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/net/imap/sasl/oauthbearer_authenticator.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ class OAuthBearerAuthenticator < OAuthAuthenticator
141141
attr_reader :oauth2_token
142142

143143
# :call-seq:
144-
# new(oauth2_token, **options) -> authenticator
145-
# new(oauth2_token:, **options) -> authenticator
144+
# new(oauth2_token, **options) -> authenticator
145+
# new(authzid, oauth2_token, **options) -> authenticator
146+
# new(oauth2_token:, **options) -> authenticator
146147
#
147148
# Creates an Authenticator for the "+OAUTHBEARER+" SASL mechanism.
148149
#
@@ -172,8 +173,9 @@ class OAuthBearerAuthenticator < OAuthAuthenticator
172173
# noting that <b><em>application protocols are allowed to
173174
# require</em></b> #authzid (<em>or other parameters, such as</em> #host
174175
# _or_ #port) <b><em>as are specific server implementations</em></b>.
175-
def initialize(oauth2_token_arg = nil, oauth2_token: nil, **args, &blk)
176-
super(**args, &blk) # handles authzid, host, port, etc
176+
def initialize(arg1 = nil, arg2 = nil, oauth2_token: nil, **args, &blk)
177+
username, oauth2_token_arg = arg2.nil? ? [nil, arg1] : [arg1, arg2]
178+
super(username: username, **args, &blk)
177179
oauth2_token && oauth2_token_arg and
178180
raise ArgumentError, "conflicting values for oauth2_token"
179181
@oauth2_token = oauth2_token || oauth2_token_arg or

0 commit comments

Comments
 (0)