lib/saml/kit/builders/response.rb in saml-kit-1.0.11 vs lib/saml/kit/builders/response.rb in saml-kit-1.0.12
- old
+ new
@@ -2,20 +2,20 @@
module Saml
module Kit
module Builders
# {include:file:lib/saml/kit/builders/templates/response.builder}
- # {include:file:spec/saml/builders/response_spec.rb}
+ # {include:file:spec/saml/kit/builders/response_spec.rb}
class Response
include XmlTemplatable
attr_reader :user, :request
attr_accessor :id, :reference_id, :now
attr_accessor :version, :status_code
attr_accessor :issuer, :destination
attr_reader :configuration
- def initialize(user, request, configuration: Saml::Kit.configuration)
+ def initialize(user, request = nil, configuration: Saml::Kit.configuration)
@user = user
@request = request
@id = ::Xml::Kit::Id.generate
@reference_id = ::Xml::Kit::Id.generate
@now = Time.now.utc
@@ -26,11 +26,11 @@
@encrypt = encryption_certificate.present?
@configuration = configuration
end
def build
- Saml::Kit::Response.new(to_xml, request_id: request.id, configuration: configuration)
+ Saml::Kit::Response.new(to_xml, request_id: request.try(:id), configuration: configuration)
end
def assertion
@assertion ||=
begin
@@ -44,18 +44,19 @@
end
private
def response_options
- {
+ options = {
ID: id,
Version: version,
IssueInstant: now.iso8601,
- Destination: destination,
Consent: Namespaces::UNSPECIFIED,
- InResponseTo: request.id,
xmlns: Namespaces::PROTOCOL,
}
+ options[:Destination] = destination if destination.present?
+ options[:InResponseTo] = request.id if request.present?
+ options
end
end
end
end
end