Sha256: c6f7afeba36363028ec74ea259ca1bf780134a03d126b05809ec44eab2b27ca7
Contents?: true
Size: 761 Bytes
Versions: 7
Compression:
Stored size: 761 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(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.map{ |k, v| "#{k}=#{Array(v).join(',')}" }.sort.join OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), secret, sorted_params) end end
Version data entries
7 entries across 7 versions & 1 rubygems