Class: Vines::Backdoor::Auth

Inherits:
Stream::Client::Auth
  • Object
show all
Defined in:
lib/vines/backdoor/auth.rb

Constant Summary collapse

INTERNAL =
"INTERNAL".freeze

Instance Method Summary collapse

Instance Method Details

#auth(node) ⇒ Object

Raises:

  • (StreamErrors::NotAuthorized)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vines/backdoor/auth.rb', line 7

def auth(node)
  raise StreamErrors::NotAuthorized unless auth?(node)

  node = node.xpath('ns:auth', 'ns' => NS).first

  if node.text.empty?
    send_auth_fail(SaslErrors::MalformedRequest.new)
  elsif stream.authentication_mechanisms.include?(node[MECHANISM])
    if node[MECHANISM] == INTERNAL
      stream.user = authenticate(node.text) or raise StreamErrors::NotAuthorized
    end
  else
    send_auth_fail(SaslErrors::InvalidMechanism.new)
  end
end