Skip to content

Commit

Permalink
Disable support for v2 authid with Jottacloud since it uses refresh t…
Browse files Browse the repository at this point in the history
…oken rotation
  • Loading branch information
albertony committed Jun 23, 2022
1 parent 39d32b5 commit 3f07323
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 17 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ def get(self, service=None):
# v2 tokens are just the provider name and the refresh token
# and they have no stored state on the server
if statetoken.version == 2:

if service.has_key('refresh-token-rotation') and service['refresh-token-rotation']:
raise Exception('Error: This service uses refresh token rotation which is not compatible with AuthID v2')

authid = 'v2:' + statetoken.service + ':' + resp['refresh_token']
dbmodel.update_fetch_token(statetoken.fetchtoken, authid)

Expand Down Expand Up @@ -427,7 +431,7 @@ def post(self):
resp = json.loads(content)
except:
error = 'Error: Invalid CLI token'
raise
raise Exception(error)

urlfetch.set_default_fetch_deadline(20)
url = service['auth-url']
Expand All @@ -454,6 +458,11 @@ def post(self):
# v2 tokens are just the provider name and the refresh token
# and they have no stored state on the server
if tokenversion == 2:

if service.has_key('refresh-token-rotation') and service['refresh-token-rotation']:
error = 'Error: This service uses refresh token rotation which is not compatible with AuthID v2'
raise Exception(error)

authid = 'v2:' + id + ':' + resp['refresh_token']
fetchtoken = dbmodel.create_fetch_token(resp)
dbmodel.update_fetch_token(fetchtoken, authid)
Expand Down Expand Up @@ -742,9 +751,13 @@ def process(self, authid):
logging.info('Caching response to: %s for %s secs, service: %s', keyid, exp_secs - 10, servicetype)

# Write the result back to the client
self.response.write(json.dumps(
{'access_token': resp['access_token'], 'expires': exp_secs, 'type': servicetype,
'v2_authid': 'v2:' + entry.service + ':' + rt}))
if service.has_key('refresh-token-rotation') and service['refresh-token-rotation']:
self.response.write(json.dumps(
{'access_token': resp['access_token'], 'expires': exp_secs, 'type': servicetype}))
else:
self.response.write(json.dumps(
{'access_token': resp['access_token'], 'expires': exp_secs, 'type': servicetype,
'v2_authid': 'v2:' + entry.service + ':' + rt}))

except:
logging.exception('handler error for ' + servicetype)
Expand Down
3 changes: 2 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@
'display': 'Jottacloud',
'client-id': "jottacli",
'auth-url': JOTTACLOUD_AUTH_URL,
'cli-token': True
'cli-token': True,
'refresh-token-rotation': True
}
}

Expand Down

0 comments on commit 3f07323

Please sign in to comment.