Sha256: 0ebed977db8c1fb218b9f201e9271c7986e781fa62a28d4ad4a931fb6f4a482b

Contents?: true

Size: 770 Bytes

Versions: 9

Compression:

Stored size: 770 Bytes

Contents

class DiscoApp::ProxyService

  # Return true iff the signature provided in the given query string matches
  # that calculated from the remaining query parameters and the given secret.
  def self.proxy_signature_is_valid?(query_string, secret)
    query_hash = Rack::Utils.parse_query(query_string)
    signature = query_hash.delete('signature').to_s
    ActiveSupport::SecurityUtils.secure_compare(self.calculated_signature(query_hash, secret), signature)
  end

  # Return the calculated signature for the given query hash and secret.
  def self.calculated_signature(query_hash, secret)
    sorted_params = query_hash.collect{ |k, v| "#{k}=#{Array(v).join(',')}" }.sort.join
    OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), secret, sorted_params)
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
disco_app-0.16.1.pre.sidekiq.pre.6.pre.release app/services/disco_app/proxy_service.rb
disco_app-0.14.1 app/services/disco_app/proxy_service.rb
disco_app-0.14.2 app/services/disco_app/proxy_service.rb
disco_app-0.15.0 app/services/disco_app/proxy_service.rb
disco_app-0.16.0 app/services/disco_app/proxy_service.rb
disco_app-0.14.4 app/services/disco_app/proxy_service.rb
disco_app-0.14.3 app/services/disco_app/proxy_service.rb
disco_app-0.16.1 app/services/disco_app/proxy_service.rb
disco_app-0.15.2 app/services/disco_app/proxy_service.rb