Sha256: 7d39eabeab82c1597e935fc13f7436558a8862e25d872d58b22677f5b265c775

Contents?: true

Size: 588 Bytes

Versions: 9

Compression:

Stored size: 588 Bytes

Contents

class DiscoApp::RequestValidationService

  def self.hmac_valid?(query_string, secret)
    query_hash = Rack::Utils.parse_query(query_string)
    hmac = query_hash.delete('hmac').to_s
    ActiveSupport::SecurityUtils.secure_compare(self.calculated_hmac(query_hash, secret), hmac)
  end

  # Return the calculated hmac for the given query hash and secret.
  def self.calculated_hmac(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/request_validation_service.rb
disco_app-0.14.1 app/services/disco_app/request_validation_service.rb
disco_app-0.14.2 app/services/disco_app/request_validation_service.rb
disco_app-0.15.0 app/services/disco_app/request_validation_service.rb
disco_app-0.16.0 app/services/disco_app/request_validation_service.rb
disco_app-0.14.4 app/services/disco_app/request_validation_service.rb
disco_app-0.14.3 app/services/disco_app/request_validation_service.rb
disco_app-0.16.1 app/services/disco_app/request_validation_service.rb
disco_app-0.15.2 app/services/disco_app/request_validation_service.rb