Created
October 20, 2018 07:14
-
-
Save evandempsey/8ff10c486e3d6b427e96facb2b3a6974 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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