Skip to content

Instantly share code, notes, and snippets.

@agriffis
Created July 18, 2015 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agriffis/bae5c8c86e57cd3bf070 to your computer and use it in GitHub Desktop.
Save agriffis/bae5c8c86e57cd3bf070 to your computer and use it in GitHub Desktop.
verify_weebly_install_params
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]&timestamp=[TIMESTAMP]&site_id=[SITE_ID]&hmac=[HMAC-SHA256]
#
# $hash_string = "user_id=[USER_ID]&timestamp=[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')
@sreenug
Copy link

sreenug commented Jul 19, 2015

This works like a charm..thanks @agriffis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment