Class: Jabber::Protocol::Authentication::NonSASL

Inherits:
Object
  • Object
show all
Defined in:
lib/jabber4r/protocol/authentication/non_sasl.rb

Overview

Class provided Non-SASL authentication on jabber server xmpp.org/extensions/xep-0078.html

Constant Summary collapse

MECHANISMS =
[:plain, :digest].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jid, password, options = {}) ⇒ NonSASL

Public: Creates new Non-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)

:stream_id - String the stream identifier (authid)
:mechanism - Symbol the name of mechnism to use

Examples

non_sasl = Jabber::Protocol::Authentication::NonSASL.new(“strech@localhost/res-1”, “my-pass-phrase”) non_sasl.plain? # => true non_sasl.to_xml # =>

<iq type=“set” id=“…”>

<query xmlns="jabber:iq:auth">
  <username>strech</username>
  <password>my-pass-phrase</password>
  <resource>res-1</resource>
</query>

</iq>

Raises:

  • (TypeError)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/jabber4r/protocol/authentication/non_sasl.rb', line 40

def initialize(jid, password, options = {})
  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 = options.fetch(:mechanism, :plain)
  @stream_id = options.fetch(:stream_id) if digest?

  raise ArgumentError,
    "Unknown authentication mechanism '#{mechanism}'," +
    " available is [#{MECHANISMS * ", "}]" unless MECHANISMS.include?(mechanism)
end

Instance Attribute Details

#jidObject (readonly)

Returns the value of attribute jid.



16
17
18
# File 'lib/jabber4r/protocol/authentication/non_sasl.rb', line 16

def jid
  @jid
end

#mechanismObject (readonly)

Returns the value of attribute mechanism.



17
18
19
# File 'lib/jabber4r/protocol/authentication/non_sasl.rb', line 17

def mechanism
  @mechanism
end

#passwordObject (readonly)

Returns the value of attribute password.



16
17
18
# File 'lib/jabber4r/protocol/authentication/non_sasl.rb', line 16

def password
  @password
end

#stream_idObject (readonly)

Returns the value of attribute stream_id.



17
18
19
# File 'lib/jabber4r/protocol/authentication/non_sasl.rb', line 17

def stream_id
  @stream_id
end

Instance Method Details

#digest?Boolean

Public: Is NonSASL object is for digest authentication

Returns boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/jabber4r/protocol/authentication/non_sasl.rb', line 66

def digest?
  mechanism == :digest
end

#dumpObject Also known as: to_xml

Public: Create XML string from NonSASL object

Returns String



73
74
75
# File 'lib/jabber4r/protocol/authentication/non_sasl.rb', line 73

def dump
  Ox.dump(send mechanism)
end

#plain?Boolean

Public: Is NonSASL object is for plain authentication

Returns boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/jabber4r/protocol/authentication/non_sasl.rb', line 59

def plain?
  mechanism == :plain
end

#to_oxObject

Public: Create Ox::Element from NonSASL object

Returns Ox::Element



81
82
83
# File 'lib/jabber4r/protocol/authentication/non_sasl.rb', line 81

def to_ox
  send(mechanism)
end