Private
Public Access
1
0

some error checking in the get_token C2 routine

This commit is contained in:
Sander Roosendaal
2017-02-23 08:11:34 +01:00
parent a46efa2831
commit 610cc7dda4
2 changed files with 14 additions and 4 deletions

View File

@@ -329,6 +329,7 @@ def do_refresh_token(refreshtoken):
# Exchange authorization code for authorization token
def get_token(code):
messg=''
scope = "user:read,results:write"
client_auth = requests.auth.HTTPBasicAuth(C2_CLIENT_ID, C2_CLIENT_SECRET)
post_data = {"grant_type": "authorization_code",
@@ -349,11 +350,15 @@ def get_token(code):
response = s.send(prepped)
token_json = response.json()
thetoken = token_json['access_token']
expires_in = token_json['expires_in']
refresh_token = token_json['refresh_token']
return [thetoken,expires_in,refresh_token]
if token_json['status_code'] == 200:
thetoken = token_json['access_token']
expires_in = token_json['expires_in']
refresh_token = token_json['refresh_token']
else:
return (0,token_json['message'])
return (thetoken,expires_in,refresh_token,messg)
# Make URL for authorization and load it
def make_authorization_url(request):