Skip to content

Instantly share code, notes, and snippets.

@evandempsey
Created October 20, 2018 07:14
Show Gist options
  • Save evandempsey/8ff10c486e3d6b427e96facb2b3a6974 to your computer and use it in GitHub Desktop.
Save evandempsey/8ff10c486e3d6b427e96facb2b3a6974 to your computer and use it in GitHub Desktop.
import hashlib
import hmac
def validate_shopify_redirect(params, secret):
"""
Validates requests/redirects from Shopify according to the rules in
http://docs.shopify.com/api/tutorials/oauth
"""
hmac_param = params["hmac"]
copied_params = params.copy()
del copied_params["hmac"]
if "signature" in copied_params:
del copied_params["signature"]
param_list = [key + "=" + value for key, value in copied_params.iteritems()]
param_list.sort()
param_string = '&'.join(param_list)
hm = hmac.new(secret, param_string, hashlib.sha256)
return hmac_param == hm.hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment