Commit e6443b7
Changed files (4)
lib
lib/saml/kit/authentication_request.rb
@@ -37,20 +37,12 @@ module Saml
def initialize(configuration = Saml::Kit.configuration)
@id = SecureRandom.uuid
@issued_at = Time.now.utc
- @acs_url = configuration.acs_url
@issuer = configuration.issuer
end
def to_xml(xml = ::Builder::XmlMarkup.new)
signature = Signature.new(id)
- xml.tag!('samlp:AuthnRequest',
- "xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol",
- "xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion",
- ID: id,
- Version: "2.0",
- IssueInstant: issued_at.strftime("%Y-%m-%dT%H:%M:%SZ"),
- AssertionConsumerServiceURL: acs_url,
- ) do
+ xml.tag!('samlp:AuthnRequest', request_options) do
signature.template(xml)
xml.tag!('saml:Issuer', issuer)
xml.tag!('samlp:NameIDPolicy', Format: "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress")
@@ -61,6 +53,20 @@ module Saml
def build
AuthenticationRequest.new(to_xml)
end
+
+ private
+
+ def request_options
+ options = {
+ "xmlns:samlp" => Namespaces::PROTOCOL,
+ "xmlns:saml" => Namespaces::ASSERTION,
+ ID: id,
+ Version: "2.0",
+ IssueInstant: issued_at.strftime("%Y-%m-%dT%H:%M:%SZ"),
+ }
+ options[:AssertionConsumerServiceURL] = acs_url if acs_url
+ options
+ end
end
end
end
lib/saml/kit/configuration.rb
@@ -4,7 +4,7 @@ module Saml
BEGIN_CERT=/-----BEGIN CERTIFICATE-----/
END_CERT=/-----END CERTIFICATE-----/
- attr_accessor :issuer, :acs_url
+ attr_accessor :issuer
attr_accessor :signature_method, :digest_method
attr_accessor :signing_certificate_pem, :signing_private_key_pem, :signing_private_key_password
spec/saml/authentication_request_spec.rb
@@ -44,12 +44,18 @@ RSpec.describe Saml::Kit::AuthenticationRequest do
</samlp:AuthnRequest>
EXAMPLE
describe "#to_xml" do
- subject { described_class::Builder.new(double(issuer: issuer, acs_url: acs_url)) }
+ subject { described_class::Builder.new(configuration) }
+ let(:configuration) do
+ config = Saml::Kit::Configuration.new
+ config.issuer = issuer
+ config
+ end
let(:issuer) { FFaker::Movie.title }
let(:acs_url) { "https://airport.dev/session/acs" }
it 'returns a valid authentication request' do
travel_to DateTime.new(2014, 7, 16, 23, 52, 45)
+ subject.acs_url = acs_url
result = Hash.from_xml(subject.to_xml)
expect(result['AuthnRequest']['ID']).to be_present
spec/saml/service_provider_metadata_spec.rb
@@ -40,4 +40,12 @@ RSpec.describe Saml::Kit::ServiceProviderMetadata do
expect(result['EntityDescriptor']['SPSSODescriptor']['KeyDescriptor']['KeyInfo']['X509Data']['X509Certificate']).to eql(Saml::Kit.configuration.stripped_signing_certificate)
end
end
+
+ describe described_class do
+ let(:builder) { described_class::Builder.new }
+
+ it 'returns each of the certificates' do
+
+ end
+ end
end