lib/net/imap/sasl/plain_authenticator.rb in net-imap-0.4.1 vs lib/net/imap/sasl/plain_authenticator.rb in net-imap-0.4.2

- old
+ new

@@ -20,13 +20,15 @@ # "Authentication identity" is the generic term used by # RFC-4422[https://tools.ietf.org/html/rfc4422]. # RFC-4616[https://tools.ietf.org/html/rfc4616] and many later RFCs abbreviate # this to +authcid+. attr_reader :username + alias authcid username # A password or passphrase that matches the #username. attr_reader :password + alias secret password # Authorization identity: an identity to act as or on behalf of. The identity # form is application protocol specific. If not provided or left blank, the # server derives an authorization identity from the authentication identity. # The server is responsible for verifying the client's credentials and @@ -40,29 +42,35 @@ attr_reader :authzid # :call-seq: # new(username, password, authzid: nil, **) -> authenticator # new(username:, password:, authzid: nil, **) -> authenticator + # new(authcid:, password:, authzid: nil, **) -> authenticator # # Creates an Authenticator for the "+PLAIN+" SASL mechanism. # # Called by Net::IMAP#authenticate and similar methods on other clients. # - # === Parameters + # ==== Parameters # - # * #username ― Identity whose +password+ is used. - # * #password ― Password or passphrase associated with this username+. - # * #authzid ― Alternate identity to act as or on behalf of. Optional. + # * #authcid ― Authentication identity that is associated with #password. # - # See attribute documentation for more details. + # #username ― An alias for #authcid. + # + # * #password ― A password or passphrase associated with the #authcid. + # + # * _optional_ #authzid ― Authorization identity to act as or on behalf of. + # + # When +authzid+ is not set, the server should derive the authorization + # identity from the authentication identity. + # + # Any other keyword parameters are quietly ignored. def initialize(user = nil, pass = nil, + authcid: nil, secret: nil, username: nil, password: nil, authzid: nil, **) - [username, user].compact.count == 1 or - raise ArgumentError, "conflicting values for username" - [password, pass].compact.count == 1 or - raise ArgumentError, "conflicting values for password" - username ||= user or raise ArgumentError, "missing username" - password ||= pass or raise ArgumentError, "missing password" + username ||= authcid || user or + raise ArgumentError, "missing username (authcid)" + password ||= secret || pass or raise ArgumentError, "missing password" raise ArgumentError, "username contains NULL" if username.include?(NULL) raise ArgumentError, "password contains NULL" if password.include?(NULL) raise ArgumentError, "authzid contains NULL" if authzid&.include?(NULL) @username = username @password = password