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