Private
Public Access
1
0

Merge tag 'v1.11' into develop

v1.11 - error checking in C2 token fetch
This commit is contained in:
Sander Roosendaal
2017-02-23 08:15:52 +01:00
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):

View File

@@ -1121,6 +1121,11 @@ def rower_process_callback(request):
return imports_view(request,message=message)
access_token = res[0]
if access_token == 0:
message = res[1]
message += ' Contact info@rowsandall.com if this behavior persists.'
return imports_view(request,message=message)
expires_in = res[1]
refresh_token = res[2]
expirydatetime = timezone.now()+datetime.timedelta(seconds=expires_in)