Skip to content

Commit 3f07323

Browse files
committed
Disable support for v2 authid with Jottacloud since it uses refresh token rotation
1 parent 39d32b5 commit 3f07323

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

main.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ def get(self, service=None):
329329
# v2 tokens are just the provider name and the refresh token
330330
# and they have no stored state on the server
331331
if statetoken.version == 2:
332+
333+
if service.has_key('refresh-token-rotation') and service['refresh-token-rotation']:
334+
raise Exception('Error: This service uses refresh token rotation which is not compatible with AuthID v2')
335+
332336
authid = 'v2:' + statetoken.service + ':' + resp['refresh_token']
333337
dbmodel.update_fetch_token(statetoken.fetchtoken, authid)
334338

@@ -427,7 +431,7 @@ def post(self):
427431
resp = json.loads(content)
428432
except:
429433
error = 'Error: Invalid CLI token'
430-
raise
434+
raise Exception(error)
431435

432436
urlfetch.set_default_fetch_deadline(20)
433437
url = service['auth-url']
@@ -454,6 +458,11 @@ def post(self):
454458
# v2 tokens are just the provider name and the refresh token
455459
# and they have no stored state on the server
456460
if tokenversion == 2:
461+
462+
if service.has_key('refresh-token-rotation') and service['refresh-token-rotation']:
463+
error = 'Error: This service uses refresh token rotation which is not compatible with AuthID v2'
464+
raise Exception(error)
465+
457466
authid = 'v2:' + id + ':' + resp['refresh_token']
458467
fetchtoken = dbmodel.create_fetch_token(resp)
459468
dbmodel.update_fetch_token(fetchtoken, authid)
@@ -742,9 +751,13 @@ def process(self, authid):
742751
logging.info('Caching response to: %s for %s secs, service: %s', keyid, exp_secs - 10, servicetype)
743752

744753
# Write the result back to the client
745-
self.response.write(json.dumps(
746-
{'access_token': resp['access_token'], 'expires': exp_secs, 'type': servicetype,
747-
'v2_authid': 'v2:' + entry.service + ':' + rt}))
754+
if service.has_key('refresh-token-rotation') and service['refresh-token-rotation']:
755+
self.response.write(json.dumps(
756+
{'access_token': resp['access_token'], 'expires': exp_secs, 'type': servicetype}))
757+
else:
758+
self.response.write(json.dumps(
759+
{'access_token': resp['access_token'], 'expires': exp_secs, 'type': servicetype,
760+
'v2_authid': 'v2:' + entry.service + ':' + rt}))
748761

749762
except:
750763
logging.exception('handler error for ' + servicetype)

settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@
234234
'display': 'Jottacloud',
235235
'client-id': "jottacli",
236236
'auth-url': JOTTACLOUD_AUTH_URL,
237-
'cli-token': True
237+
'cli-token': True,
238+
'refresh-token-rotation': True
238239
}
239240
}
240241

0 commit comments

Comments
 (0)