Created
January 10, 2014 15:16
-
-
Save lepture/8356171 to your computer and use it in GitHub Desktop.
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 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