Add KeyError check

This commit is contained in:
Micke Nordin 2024-01-13 15:52:01 +01:00
parent 1226cbbf11
commit 913980a027
Signed by untrusted user: Micke
GPG key ID: 0DA0A7A5708FE257

View file

@ -30,16 +30,19 @@ hub:
spawner.environment['NEXTCLOUD_ACCESS_TOKEN'] = access_token
async def refresh_user(self, user, handler=None):
access_token = self.user_dict[user.name]['access_token']
refresh_token = self.user_dict[user.name]['refresh_token']
token_response = self.user_dict[user.name]['token_response']
now = time.time()
expires = self.user_dict[user.name]['token_expires']
if now >= expires:
print(f'Time is: {now}, token expired: {expires}')
try:
access_token = self.user_dict[user.name]['access_token']
refresh_token = self.user_dict[user.name]['refresh_token']
token_response = self.user_dict[user.name]['token_response']
now = time.time()
expires = self.user_dict[user.name]['token_expires']
if now >= expires:
print(f'Time is: {now}, token expired: {expires}')
return False
print(f'Time is: {now}, token expires: {expires}')
return True
except KeyError:
return False
print(f'Time is: {now}, token expires: {expires}')
return True
c.JupyterHub.authenticator_class = NextcloudOAuthenticator
c.NextcloudOAuthenticator.client_id = os.environ['NEXTCLOUD_CLIENT_ID']