Created
January 31, 2017 02:50
-
-
Save eleloya23/9b7e76c65a6275e3a113640c763be100 to your computer and use it in GitHub Desktop.
Mode Analytics Easier Url Signature Function
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 md5 | |
import hmac | |
import base64 | |
import hashlib | |
import time | |
def sign_url(url, key, secret): | |
request_type = 'GET' | |
content_type = '' | |
content_body = '' | |
content_hash = md5.new(content_body).digest() | |
content_digest = base64.encodestring(content_hash).strip() | |
epoch = str(int(time.time())) | |
url = '%s×tamp=%s' % (url, epoch) | |
request_string = ','.join([request_type, content_type, content_digest, url, epoch]) | |
signature = hmac.new(secret, msg=request_string, digestmod=hashlib.sha256).hexdigest() | |
signed_url = '%s&signature=%s' % (url, signature) | |
return signed_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment