Skip to content

Instantly share code, notes, and snippets.

@lepture
Created January 10, 2014 15:16
Show Gist options
  • Select an option

  • Save lepture/8356171 to your computer and use it in GitHub Desktop.

Select an option

Save lepture/8356171 to your computer and use it in GitHub Desktop.
import time
import hmac
import hashlib
import json
from base64 import urlsafe_b64encode
def create_token(access_key, secret_key, scope):
deadline = int(time.time()) + 50000
data = {
'scope': scope,
'deadline': deadline,
}
data = json.dumps(data)
encoded_data = urlsafe_b64encode(data)
signature = hmac.new(secret_key, encoded_data, hashlib.sha1)
encoded_signature = urlsafe_b64encode(signature.digest())
return '%s:%s:%s' % (
access_key, encoded_signature, encoded_data
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment