Class: OmniAuth::Strategies::Latvija::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/omniauth/strategies/latvija/response.rb

Constant Summary collapse

ASSERTION =
"urn:oasis:names:tc:SAML:1.0:assertion"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, options = {}) ⇒ Response

Returns a new instance of Response.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
# File 'lib/omniauth/strategies/latvija/response.rb', line 9

def initialize(response, options = {})
  raise ArgumentError.new("Response cannot be nil") if response.nil?
  self.options  = options
  self.response = response
  self.document = OmniAuth::Strategies::Latvija::SignedDocument.new(response)
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



7
8
9
# File 'lib/omniauth/strategies/latvija/response.rb', line 7

def document
  @document
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/omniauth/strategies/latvija/response.rb', line 7

def options
  @options
end

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/omniauth/strategies/latvija/response.rb', line 7

def response
  @response
end

Instance Method Details

#attributesObject

A hash of alle the attributes with the response. Assuming there is only one value for each key



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/omniauth/strategies/latvija/response.rb', line 27

def attributes
  @attributes ||= begin
    result = {}

    stmt_element = REXML::XPath.first(document, "//a:Assertion/a:AttributeStatement", { "a" => ASSERTION })
    return {} if stmt_element.nil?

    stmt_element.elements.each do |attr_element|
      name  = attr_element.attributes["AttributeName"]
      value = attr_element.elements.first.text

      result[name] = value
    end

    result
  end
end

#authentication_methodObject



20
21
22
23
24
# File 'lib/omniauth/strategies/latvija/response.rb', line 20

def authentication_method
  @authentication_method ||= begin
    REXML::XPath.first(document, "//saml:AuthenticationStatement").attributes['AuthenticationMethod']
  end
end

#validate!Object



16
17
18
# File 'lib/omniauth/strategies/latvija/response.rb', line 16

def validate!
  document.validate!(fingerprint)
end