Created
July 18, 2015 15:33
-
-
Save agriffis/bae5c8c86e57cd3bf070 to your computer and use it in GitHub Desktop.
verify_weebly_install_params
This file contains 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 verify_weebly_install_params(params, secret): | |
""" | |
Verifies the hmac of params on the Weebly install URL. | |
""" | |
# https://dev.weebly.com/oauth2.html | |
# | |
# [MANIFEST_CALLBACK_URL]?user_id=[USER_ID]×tamp=[TIMESTAMP]&site_id=[SITE_ID]&hmac=[HMAC-SHA256] | |
# | |
# $hash_string = "user_id=[USER_ID]×tamp=[TIMESTAMP]&site_id=[SITE_ID]"; | |
# $hash = hash_hmac('sha256', $hash_string, SECRET_KEY); | |
message = '&'.join('{}={}'.format(k, params.get(k, '')) | |
for k in ['user_id', 'timestamp', 'site_id']) | |
h = hmac.new(secret.encode('ascii'), | |
message.encode('ascii', 'ignore'), | |
hashlib.sha256) | |
return h.hexdigest() == params.get('hmac') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works like a charm..thanks @agriffis