Class: Saml::Kit::LogoutResponse

Inherits:
Document
  • Object
show all
Includes:
Respondable
Defined in:
lib/saml/kit/logout_response.rb

Overview

This class is used to parse a LogoutResponse SAML document.

document = Saml::Kit::LogoutResponse.new(raw_xml)

require_relative './principal'

RSpec.describe "Logout Response" do
  let(:user) { Principal.new(id: SecureRandom.uuid, email: "hello@example.com") }

  it 'generates a logout response' do
    xml = Saml::Kit::Metadata.build_xml do |builder|
      builder.contact_email = 'hi@example.com'
      builder.organization_name = "Acme, Inc"
      builder.organization_url = 'https://www.example.com'
      builder.build_identity_provider do |x|
        x.add_single_sign_on_service('https://www.example.com/login', binding: :http_post)
        x.add_single_sign_on_service('https://www.example.com/login', binding: :http_redirect)
        x.add_single_logout_service('https://www.example.com/logout', binding: :http_post)
        x.name_id_formats = [ Saml::Kit::Namespaces::EMAIL_ADDRESS ]
        x.attributes << :id
        x.attributes << :email
      end
      builder.build_service_provider do |x|
        x.add_assertion_consumer_service('https://www.example.com/consume', binding: :http_post)
        x.add_single_logout_service('https://www.example.com/logout', binding: :http_post)
      end
    end

    idp = Saml::Kit::IdentityProviderMetadata.new(xml)
    url, saml_params = idp.logout_request_for(user, binding: :http_post)
    uri = URI.parse("#{url}?#{saml_params.map { |(x, y)| "#{x}=#{y}" }.join('&')}")

    raw_params = Hash[uri.query.split("&amp;").map { |x| x.split("=", 2) }].symbolize_keys

    binding = idp.single_logout_service_for(binding: :http_post)
    saml_request = binding.deserialize(raw_params)
    sp = Saml::Kit::ServiceProviderMetadata.new(xml)
    allow(saml_request).to receive(:provider).and_return(sp)
    url, saml_params = saml_request.response_for(binding: :http_post)
    expect(url).to eql("https://www.example.com/logout")
    expect(saml_params['SAMLResponse']).to be_present
  end
end

Constant Summary

Constants inherited from Document

Document::CONSTRUCTORS, Document::XPATH

Constants included from XsdValidatable

XsdValidatable::METADATA_XSD, XsdValidatable::PROTOCOL_XSD

Constants included from XmlParseable

XmlParseable::NAMESPACES

Instance Attribute Summary

Attributes included from Respondable

#request_id

Attributes inherited from Document

#name, #registry

Instance Method Summary collapse

Methods included from Respondable

#in_response_to, #status_code, #status_message, #success?

Methods inherited from Document

#destination, #id, #issue_instant, #issuer, to_saml_document, #version

Methods included from XmlParseable

#present?, #to_h, #to_s, #to_xhtml, #to_xml

Methods included from Trustable

#signed?, #trusted?

Methods included from Validatable

#each_error

Constructor Details

#initialize(xml, request_id: nil, configuration: Saml::Kit.configuration) ⇒ LogoutResponse

Returns a new instance of LogoutResponse.



13
14
15
16
17
18
# File 'lib/saml/kit/logout_response.rb', line 13

def initialize(
  xml, request_id: nil, configuration: Saml::Kit.configuration
)
  @request_id = request_id
  super(xml, name: 'LogoutResponse', configuration: configuration)
end