Commit 1954f81

mo <mo.khan@gmail.com>
2017-11-14 00:28:33
render spinner on logout.
1 parent b8b6264
lib/saml/kit/authentication_request.rb
@@ -128,14 +128,14 @@ module Saml
       end
 
       class Builder
-        attr_accessor :id, :issued_at, :issuer, :acs_url, :name_id_format
+        attr_accessor :id, :now, :issuer, :acs_url, :name_id_format
         attr_reader :sign
 
-        def initialize(configuration = Saml::Kit.configuration, sign: true)
+        def initialize(user = nil, configuration: Saml::Kit.configuration, sign: true)
           @id = SecureRandom.uuid
-          @issued_at = Time.now.utc
           @issuer = configuration.issuer
           @name_id_format = Namespaces::PERSISTENT
+          @now = Time.now.utc
           @sign = sign
         end
 
@@ -161,7 +161,7 @@ module Saml
             "xmlns:saml" => Namespaces::ASSERTION,
             ID: "_#{id}",
             Version: "2.0",
-            IssueInstant: issued_at.utc.iso8601,
+            IssueInstant: now.utc.iso8601,
           }
           options[:AssertionConsumerServiceURL] = acs_url if acs_url.present?
           options
lib/saml/kit/identity_provider_metadata.rb
@@ -39,8 +39,8 @@ module Saml
         end
       end
 
-      def build_request(type)
-        builder = type::Builder.new(sign: want_authn_requests_signed)
+      def build_request(type, user = nil)
+        builder = type::Builder.new(user, sign: want_authn_requests_signed)
         yield builder if block_given?
         builder.build
       end
lib/saml/kit/logout_request.rb
@@ -5,7 +5,7 @@ module Saml
       include XsdValidatable
       include ActiveModel::Validations
       validates_presence_of :content
-      validates_presence_of :single_logout_service, if: :logout_request?
+      validates_presence_of :single_logout_service, if: :logout?
       validate :must_be_request
       validate :must_have_valid_signature
       validate :must_be_registered
@@ -104,11 +104,11 @@ module Saml
       def must_be_request
         return if to_h.nil?
 
-        errors[:base] << error_message(:invalid) unless logout_request?
+        errors[:base] << error_message(:invalid) unless logout?
       end
 
       def must_be_registered
-        return unless logout_request?
+        return unless logout?
         if provider.nil?
           errors[:provider] << error_message(:unregistered)
           return
@@ -121,7 +121,7 @@ module Saml
         matches_xsd?(PROTOCOL_XSD)
       end
 
-      def logout_request?
+      def logout?
         return false if to_xml.blank?
         to_h[name].present?
       end
@@ -131,13 +131,13 @@ module Saml
         attr_accessor :sign
         attr_reader :user
 
-        def initialize(user, configuration: Saml::Kit.configuration)
+        def initialize(user, configuration: Saml::Kit.configuration, sign: true)
           @user = user
           @id = SecureRandom.uuid
           @issuer = configuration.issuer
           @name_id_format = Saml::Kit::Namespaces::PERSISTENT
           @now = Time.now.utc
-          @sign = true
+          @sign = sign
         end
 
         def to_xml
spec/saml/authentication_request_spec.rb
@@ -22,7 +22,7 @@ RSpec.describe Saml::Kit::AuthenticationRequest do
   it { expect(subject.name_id_format).to eql(name_id_format) }
 
   describe "#to_xml" do
-    subject { described_class::Builder.new(configuration) }
+    subject { described_class::Builder.new(configuration: configuration) }
     let(:configuration) do
       config = Saml::Kit::Configuration.new
       config.issuer = issuer