Sha256: 602099f8e5c8a35856ed186e3b084b85c62ec0fbcdd2a7318abd96e64781ab36

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Saml
  module Kit
    module Bindings
      # {include:file:spec/saml/bindings/binding_spec.rb}
      class Binding
        attr_reader :binding, :location

        def initialize(binding:, location:)
          @binding = binding
          @location = location
        end

        def binding?(other)
          binding == other
        end

        def serialize(*)
          []
        end

        def deserialize(_params)
          raise ArgumentError, 'Unsupported binding'
        end

        def to_h
          { binding: binding, location: location }
        end

        def ==(other)
          to_s == other.to_s
        end

        def eql?(other)
          self == other
        end

        def hash
          to_s.hash
        end

        def to_s
          "#{location}#{binding}"
        end

        def inspect
          to_h.inspect
        end

        protected

        def saml_param_from(params)
          parameters = {
            SAMLRequest: params[:SAMLRequest] || params['SAMLRequest'],
            SAMLResponse: params[:SAMLResponse] || params['SAMLResponse'],
          }
          if parameters[:SAMLRequest].present?
            parameters[:SAMLRequest]
          elsif parameters[:SAMLResponse].present?
            parameters[:SAMLResponse]
          else
            raise ArgumentError, 'SAMLRequest or SAMLResponse parameter is required.'
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
saml-kit-1.0.11 lib/saml/kit/bindings/binding.rb
saml-kit-1.0.10 lib/saml/kit/bindings/binding.rb