Class: Saml::Kit::IdentityProviderMetadata
- Defined in:
- lib/saml/kit/identity_provider_metadata.rb
Overview
This class parses the IDPSSODescriptor from a SAML metadata document.
raw_xml = <<-XML
metadata = Saml::Kit::IdentityProviderMetadata.new(raw_xml) puts metadata.entity_id
It can also be used to generate IDP metadata.
= Saml::Kit::IdentityProviderMetadata.build do |builder|
builder.entity_id = "my-entity-id"
end
puts .to_xml
For more details on generating metadata see Metadata.
Example:
RSpec.describe "Identity Provider Metadata" do
it 'produces identity provider metadata' 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
end
expect(xml).to be_present
expect(xml).to have_xpath("//md:EntityDescriptor//md:IDPSSODescriptor")
expect(xml).to_not have_xpath("//md:EntityDescriptor//md:SPSSODescriptor")
end
end
Constant Summary
Constants included from XsdValidatable
XsdValidatable::METADATA_XSD, XsdValidatable::PROTOCOL_XSD
Constants included from XmlParseable
Instance Attribute Summary
Attributes inherited from Metadata
Instance Method Summary collapse
-
#attributes ⇒ Object
Returns each of the Attributes in the metadata.
-
#initialize(xml) ⇒ IdentityProviderMetadata
constructor
A new instance of IdentityProviderMetadata.
-
#login_request_for(binding:, relay_state: nil, configuration: Saml::Kit.configuration) ⇒ Array
Creates a AuthnRequest document for the specified binding.
-
#single_sign_on_service_for(binding:) ⇒ Object
Returns a SingleSignOnService elements with the specified binding.
-
#single_sign_on_services ⇒ Object
Returns each of the SingleSignOnService elements.
-
#want_authn_requests_signed ⇒ Object
Returns the IDPSSODescriptor/@WantAuthnRequestsSigned attribute.
Methods inherited from Metadata
#certificates, #contact_person_company, #encryption_certificates, #entity_id, from, #logout_request_for, #matches?, #name_id_formats, #organization, #organization_name, #organization_url, #service_for, #services, #signature, #signing_certificates, #single_logout_service_for, #single_logout_services, #verify
Methods included from XmlParseable
#present?, #to_h, #to_s, #to_xhtml, #to_xml
Methods included from Validatable
Constructor Details
#initialize(xml) ⇒ IdentityProviderMetadata
Returns a new instance of IdentityProviderMetadata.
51 52 53 |
# File 'lib/saml/kit/identity_provider_metadata.rb', line 51 def initialize(xml) super('IDPSSODescriptor', xml) end |
Instance Method Details
#attributes ⇒ Object
Returns each of the Attributes in the metadata.
77 78 79 80 81 82 83 84 |
# File 'lib/saml/kit/identity_provider_metadata.rb', line 77 def attributes search("/md:EntityDescriptor/md:#{name}/saml:Attribute").map do |item| { format: item.attribute('NameFormat').try(:value), name: item.attribute('Name').value, } end end |
#login_request_for(binding:, relay_state: nil, configuration: Saml::Kit.configuration) ⇒ Array
Creates a AuthnRequest document for the specified binding.
use for generating the request.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/saml/kit/identity_provider_metadata.rb', line 93 def login_request_for( binding:, relay_state: nil, configuration: Saml::Kit.configuration ) builder = AuthenticationRequest.builder(configuration: configuration) do |x| x. = want_authn_requests_signed yield x if block_given? end request_binding = single_sign_on_service_for(binding: binding) request_binding.serialize(builder, relay_state: relay_state) end |
#single_sign_on_service_for(binding:) ⇒ Object
Returns a SingleSignOnService elements with the specified binding.
72 73 74 |
# File 'lib/saml/kit/identity_provider_metadata.rb', line 72 def single_sign_on_service_for(binding:) service_for(binding: binding, type: 'SingleSignOnService') end |
#single_sign_on_services ⇒ Object
Returns each of the SingleSignOnService elements.
65 66 67 |
# File 'lib/saml/kit/identity_provider_metadata.rb', line 65 def single_sign_on_services services('SingleSignOnService') end |
#want_authn_requests_signed ⇒ Object
Returns the IDPSSODescriptor/@WantAuthnRequestsSigned attribute.
56 57 58 59 60 61 62 |
# File 'lib/saml/kit/identity_provider_metadata.rb', line 56 def want_authn_requests_signed xpath = "/md:EntityDescriptor/md:#{name}" attribute = at_xpath(xpath).attribute('WantAuthnRequestsSigned') return true if attribute.nil? attribute.text.casecmp('true').zero? end |