Sha256: de85eeac37aaaafef0b5b64b98517e7231a40145457424e1b69d4c427ae9870c

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module Saml
  module Kit
    module Bindings
      class UrlBuilder
        include Serializable

        def initialize(private_key: Saml::Kit.configuration.signing_private_key)
          @private_key = private_key
        end

        def build(saml_document, relay_state: nil)
          payload = canonicalize(saml_document, relay_state)
          "#{saml_document.destination}?#{payload}&Signature=#{signature_for(payload)}"
        end

        private

        attr_reader :private_key

        def signature_for(payload)
          encode(private_key.sign(OpenSSL::Digest::SHA256.new, payload))
        end

        def canonicalize(saml_document, relay_state)
          {
            saml_document.query_string_parameter => serialize(saml_document.to_xml),
            'RelayState' => relay_state,
            'SigAlg' => Saml::Kit::Namespaces::SHA256,
          }.map do |(key, value)|
            value.present? ? "#{key}=#{escape(value)}" : nil
          end.compact.join('&')
        end

        def serialize(value)
          encode(deflate(value))
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
saml-kit-0.2.3 lib/saml/kit/bindings/url_builder.rb
saml-kit-0.2.2 lib/saml/kit/bindings/url_builder.rb
saml-kit-0.2.1 lib/saml/kit/bindings/url_builder.rb
saml-kit-0.2.0 lib/saml/kit/bindings/url_builder.rb