Skip to content

Instantly share code, notes, and snippets.

@eleloya23
Created January 31, 2017 02:50
Show Gist options
  • Save eleloya23/9b7e76c65a6275e3a113640c763be100 to your computer and use it in GitHub Desktop.
Save eleloya23/9b7e76c65a6275e3a113640c763be100 to your computer and use it in GitHub Desktop.
Mode Analytics Easier Url Signature Function
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&timestamp=%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