Class: Saml::Kit::AuthenticationRequest
- Includes:
- Requestable
- Defined in:
- lib/saml/kit/authentication_request.rb
Overview
This class can be used to parse a SAML AuthnRequest or generate one.
To generate an AuthnRequest use the builder API.
request = AuthenticationRequest.build do |builder|
builder.name_id_format = [Saml::Kit::Namespaces::EMAIL_ADDRESS]
end
<?xml version="1.0" encoding="UTF-8"?>
<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_ca3a0e72-9530-41f1-9518-c53716de88b2" Version="2.0" IssueInstant="2017-12-19T16:27:44Z" Destination="http://hartmann.info" AssertionConsumerServiceURL="https://carroll.com/acs">
<saml:Issuer>Day of the Dangerous Cousins</saml:Issuer>
<samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"/>
</samlp:AuthnRequest>
Example:
Constant Summary
Constants inherited from Document
Document::NAMESPACES, Document::PROTOCOL_XSD, Document::XPATH
Instance Attribute Summary
Attributes inherited from Document
Instance Method Summary collapse
-
#assertion_consumer_service_url ⇒ Object
Extract the AssertionConsumerServiceURL from the AuthnRequest <samlp:AuthnRequest AssertionConsumerServiceURL=“carroll.com/acs”></samlp:AuthnRequest>.
-
#initialize(xml, configuration: Saml::Kit.configuration) ⇒ AuthenticationRequest
constructor
Create an instance of an AuthnRequest document.
- #name_id_format ⇒ Object
-
#name_id_policy ⇒ Object
Extract the NameIDPolicy from the AuthnRequest <samlp:AuthnRequest> <samlp:NameIDPolicy Format=“urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress”/> </samlp:AuthnRequest>.
-
#response_for(user, binding:, relay_state: nil, configuration: Saml::Kit.configuration) ⇒ Object
Generate a Response for a specific user.
Methods inherited from Document
#destination, #id, #issue_instant, #issuer, #to_h, #to_s, to_saml_document, #to_xhtml, #to_xml, #version
Methods included from Trustable
Constructor Details
#initialize(xml, configuration: Saml::Kit.configuration) ⇒ AuthenticationRequest
Create an instance of an AuthnRequest document.
29 30 31 |
# File 'lib/saml/kit/authentication_request.rb', line 29 def initialize(xml, configuration: Saml::Kit.configuration) super(xml, name: 'AuthnRequest', configuration: configuration) end |
Instance Method Details
#assertion_consumer_service_url ⇒ Object
Extract the AssertionConsumerServiceURL from the AuthnRequest
<samlp:AuthnRequest AssertionConsumerServiceURL="https://carroll.com/acs"></samlp:AuthnRequest>
35 36 37 |
# File 'lib/saml/kit/authentication_request.rb', line 35 def assertion_consumer_service_url at_xpath('./*/@AssertionConsumerServiceURL').try(:value) end |
#name_id_format ⇒ Object
39 40 41 |
# File 'lib/saml/kit/authentication_request.rb', line 39 def name_id_format name_id_policy end |
#name_id_policy ⇒ Object
Extract the NameIDPolicy from the AuthnRequest
<samlp:AuthnRequest>
<samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"/>
</samlp:AuthnRequest>
47 48 49 |
# File 'lib/saml/kit/authentication_request.rb', line 47 def name_id_policy at_xpath('./*/samlp:NameIDPolicy/@Format').try(:value) end |
#response_for(user, binding:, relay_state: nil, configuration: Saml::Kit.configuration) ⇒ Object
Generate a Response for a specific user.
55 56 57 58 59 60 61 62 |
# File 'lib/saml/kit/authentication_request.rb', line 55 def response_for(user, binding:, relay_state: nil, configuration: Saml::Kit.configuration) response_binding = provider.assertion_consumer_service_for(binding: binding) builder = Saml::Kit::Response.builder(user, self, configuration: configuration) do |x| x. = provider.want_assertions_signed yield x if block_given? end response_binding.serialize(builder, relay_state: relay_state) end |