Class: Jabber::Protocol::Authentication::SASL
- Inherits:
-
Object
- Object
- Jabber::Protocol::Authentication::SASL
- Defined in:
- lib/jabber4r/protocol/authentication/sasl.rb
Overview
Class provided SASL authentication on jabber server
Constant Summary collapse
- MECHANISMS =
Full list of mechanisms www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml
[:plain].freeze
Instance Attribute Summary collapse
-
#jid ⇒ Object
readonly
Returns the value of attribute jid.
-
#mechanism ⇒ Object
readonly
Returns the value of attribute mechanism.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
Instance Method Summary collapse
-
#dump ⇒ Object
(also: #to_xml)
Public: Create XML string from SASL object.
-
#initialize(jid, password, options = {}) ⇒ SASL
constructor
Public: Creates new SASL authentication object.
-
#plain? ⇒ Boolean
Public: Is SASL object is for plain authentication.
-
#to_ox ⇒ Object
Public: Create Ox::Element from SASL object.
Constructor Details
#initialize(jid, password, options = {}) ⇒ SASL
Public: Creates new SASL authentication object
jid - [Jabber::JID|String] the jid of jabber server user password - String the user password options - Hash the authentication options (default: Empty hash)
:mechanism - Symbol the name of mechnism to use
Examples
non_sasl = Jabber::Protocol::Authentication::SASL.new(“strech@localhost/res-1”, “my-pass-phrase”) non_sasl.plain? # => true non_sasl.to_xml # =>
<auth xmlns=“urn:ietf:params:xml:ns:xmpp-sasl” mechanism=“PLAIN”>biwsbj1qdWxpZXQscj1vTXNUQUF3QUFBQU1BQUFBTlAwVEFBQUFBQUJQVTBBQQ==</auth>
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 34 def initialize(jid, password, = {}) raise TypeError, "Class(Jabber::JID) or Class(String) expected," + " but #{jid.class} was given" unless jid.is_a?(Jabber::JID) || jid.is_a?(String) @jid = jid.is_a?(Jabber::JID) ? jid : Jabber::JID.new(jid) @password = password @mechanism = .fetch(:mechanism, :plain) raise ArgumentError, "Unknown authentication mechanism '#{mechanism}'," + " available is [#{MECHANISMS * ", "}]" unless MECHANISMS.include?(mechanism) end |
Instance Attribute Details
#jid ⇒ Object (readonly)
Returns the value of attribute jid.
17 18 19 |
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 17 def jid @jid end |
#mechanism ⇒ Object (readonly)
Returns the value of attribute mechanism.
18 19 20 |
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 18 def mechanism @mechanism end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
17 18 19 |
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 17 def password @password end |
Instance Method Details
#dump ⇒ Object Also known as: to_xml
Public: Create XML string from SASL object
Returns String
59 60 61 |
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 59 def dump Ox.dump(send mechanism) end |
#plain? ⇒ Boolean
Public: Is SASL object is for plain authentication
Returns boolean
52 53 54 |
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 52 def plain? mechanism == :plain end |
#to_ox ⇒ Object
Public: Create Ox::Element from SASL object
Returns Ox::Element
67 68 69 |
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 67 def to_ox send(mechanism) end |