Sha256: 5027d9b272db696b53128e0533423467d05d34bbd20df1d160e49c1ce2596d0f
Contents?: true
Size: 1.07 KB
Versions: 8
Compression:
Stored size: 1.07 KB
Contents
module ShopifyApp module AppProxyVerification extend ActiveSupport::Concern included do if Rails.version >= '5.0' skip_before_action :verify_authenticity_token, raise: false else skip_before_action :verify_authenticity_token end before_action :verify_proxy_request end def verify_proxy_request return head :unauthorized unless query_string_valid?(request.query_string) end private def query_string_valid?(query_string) query_hash = Rack::Utils.parse_query(query_string) signature = query_hash.delete('signature') return false if signature.nil? ActiveSupport::SecurityUtils.secure_compare( calculated_signature(query_hash), signature ) end def calculated_signature(query_hash_without_signature) sorted_params = query_hash_without_signature.collect{|k,v| "#{k}=#{Array(v).join(',')}"}.sort.join OpenSSL::HMAC.hexdigest( OpenSSL::Digest.new('sha256'), ShopifyApp.configuration.secret, sorted_params ) end end end
Version data entries
8 entries across 8 versions & 1 rubygems