diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index 9cd176d1..23bf374f 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -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): diff --git a/rowers/views.py b/rowers/views.py index 7ef32f3a..929edfb7 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -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)