Module: Samlr::Tools::LogoutResponseBuilder

Defined in:
lib/samlr/tools/logout_response_builder.rb

Overview

Use this for building the SAML logout response XML

Class Method Summary collapse

Class Method Details

.build(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/samlr/tools/logout_response_builder.rb', line 7

def self.build(options = {})
  status_code = options[:status_code] || "urn:oasis:names:tc:SAML:2.0:status:Success"
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.LogoutResponse(logout_response_options(options)) do
      xml.doc.root.namespace = xml.doc.root.namespace_definitions.find { |ns| ns.prefix == "samlp" }
      xml["saml"].Issuer(options[:issuer]) if options[:issuer]
      xml["samlp"].Status { |xml| xml["samlp"].StatusCode("Value" => status_code) }
    end
  end
  builder.to_xml(COMPACT)
end

.logout_response_options(options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/samlr/tools/logout_response_builder.rb', line 19

def self.logout_response_options(options)
  result = {
    "xmlns:samlp" => NS_MAP["samlp"],
    "xmlns:saml" => NS_MAP["saml"],
    "ID" => Samlr::Tools.uuid,
    "IssueInstant" => Samlr::Tools::Timestamp.stamp,
    "Version" => "2.0"
  }
  result["InResponseTo"] = options[:in_response_to] if options[:in_response_to]
  result["Destination"] = options[:destination]     if options[:destination]
  result
end