Class: Saml::Kit::AuthenticationRequest

Inherits:
Document
  • Object
show all
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

<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&quot; AssertionConsumerServiceURL="https://carroll.com/acs&quot;&gt; saml:IssuerDay of the Dangerous Cousins</saml:Issuer> <samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"/> </samlp:AuthnRequest>

Constant Summary collapse

Builder =
Deprecated.

Use Builders::AuthenticationRequest instead of this.

ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Saml::Kit::AuthenticationRequest::Builder', 'Saml::Kit::Builders::AuthenticationRequest')

Constants inherited from Document

Document::PROTOCOL_XSD

Instance Method Summary collapse

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

#signed?, #trusted?

Constructor Details

#initialize(xml, configuration: Saml::Kit.configuration) ⇒ AuthenticationRequest

Create an instance of an AuthnRequest document.

Parameters:

  • xml (String) —

    the raw xml.

  • configuration (Saml::Kit::Configuration) (defaults to: Saml::Kit.configuration) —

    defaults to the global configuration.



23
24
25
# File 'lib/saml/kit/authentication_request.rb', line 23

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&quot;&gt;&lt;/samlp:AuthnRequest&gt;



29
30
31
# File 'lib/saml/kit/authentication_request.rb', line 29

def assertion_consumer_service_url
  to_h[name]['AssertionConsumerServiceURL']
end

#name_id_format ⇒ Object

Extract the NameIDPolicy from the AuthnRequest samlp:AuthnRequest <samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"/> </samlp:AuthnRequest>



37
38
39
# File 'lib/saml/kit/authentication_request.rb', line 37

def name_id_format
  to_h[name]['NameIDPolicy']['Format']
end

#response_for(user, binding:, relay_state: nil) ⇒ Object

Generate a Response for a specific user.

Parameters:

  • user (Object) —

    this is a custom user object that can be used for generating a nameid and assertion attributes.

  • binding (Symbol) —

    the SAML binding to use :http_post or :http_redirect.



44
45
46
47
48
49
50
51
# File 'lib/saml/kit/authentication_request.rb', line 44

def response_for(user, binding:, relay_state: nil)
  response_binding = provider.assertion_consumer_service_for(binding: binding)
  builder = Saml::Kit::Response.builder(user, self) do |x|
    x.embed_signature = provider.want_assertions_signed
    yield x if block_given?
  end
  response_binding.serialize(builder, relay_state: relay_state)
end