Class: Samlr::Tools::MetadataBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/samlr/tools/metadata_builder.rb

Overview

Builds you some SP metadata. Accepts a hash with the below keys. No support for arrays of name id formats or asserion consumer services, build it if you need it.

:entity_id            => "https://sp.example.org/saml", # mandatory
:name_identity_format => Samlr::EMAIL_FORMAT,
:consumer_service_url => "https://sp.example.org/saml"

Class Method Summary collapse

Class Method Details

.build(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/samlr/tools/metadata_builder.rb', line 12

def self.build(options = {})
  name_identity_format     = options[:name_identity_format]
  consumer_service_url     = options[:consumer_service_url]
  consumer_service_binding = options[:consumer_service_binding] || "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"

  # Mandatory
  entity_id                 = options.fetch(:entity_id)

  builder = Nokogiri::XML::Builder.new do |xml|
    xml.EntityDescriptor("xmlns:md" => NS_MAP["md"], "entityID" => entity_id) do
      xml.doc.root.namespace = xml.doc.root.namespace_definitions.find { |ns| ns.prefix == "md" }

      xml["md"].SPSSODescriptor("protocolSupportEnumeration" => NS_MAP["samlp"]) do
        unless name_identity_format.nil?
          xml["md"].NameIDFormat(name_identity_format)
        end

        unless consumer_service_url.nil?
          xml["md"].AssertionConsumerService("index" => "0", "Binding" => consumer_service_binding, "Location" => consumer_service_url)
        end
      end
    end
  end

  builder.to_xml(COMPACT)
end