Last active
January 2, 2016 01:29
-
-
Save mehdimehdi/8230520 to your computer and use it in GitHub Desktop.
Log a user in (create an account if user does not exists)
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 requests | |
import base64 | |
import hashlib | |
import hmac | |
import simplejson | |
import time | |
PUNCHTAB_CLIENT_ID = '2128281015' #client_id | |
PUNCHTAB_SECRET_KEY = '<YOUR SECRET KEY>' | |
PUNCHTAB_ACCESS_KEY = 'c370b56450e41a8f689fffb2374e7ef4' #key | |
user = simplejson.dumps({'id': '2', 'first_name': 'John', 'last_name': 'Doe', | |
'email': '[email protected]', | |
'avatar_link': 'http://s3.amazonaws.com/punchtab-static/zzzzzz/img/team/lewolf.jpg'}) | |
auth_request = base64.b64encode(user) | |
timestamp = int(time.time()) | |
signature = hmac.HMAC(PUNCHTAB_SECRET_KEY, '%s %s' % (auth_request, timestamp), hashlib.sha1).hexdigest() | |
payload = dict(client_id=PUNCHTAB_CLIENT_ID , | |
key=PUNCHTAB_ACCESS_KEY, auth_request=auth_request, | |
timestamp= timestamp, signature = signature) | |
r = requests.post('https://api.punchtab.com/v1/auth/sso',data=payload) | |
print r.json() | |
'''returns | |
{ | |
u'status': u'connected', | |
u'authResponse': { | |
u'expiresIn': 1209600, | |
u'newUser': False, | |
u'userID': u'2_56730', | |
u'uid': u'4455181', | |
u'accessToken': u'e72cf11d3c92428ba8dea5b53370553b' | |
} | |
} | |
''' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment