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 spawner.environment['NEXTCLOUD_ACCESS_TOKEN'] = access_token
async def refresh_user(self, user, handler=None): async def refresh_user(self, user, handler=None):
access_token = self.user_dict[user.name]['access_token'] try:
refresh_token = self.user_dict[user.name]['refresh_token'] access_token = self.user_dict[user.name]['access_token']
token_response = self.user_dict[user.name]['token_response'] refresh_token = self.user_dict[user.name]['refresh_token']
now = time.time() token_response = self.user_dict[user.name]['token_response']
expires = self.user_dict[user.name]['token_expires'] now = time.time()
if now >= expires: expires = self.user_dict[user.name]['token_expires']
print(f'Time is: {now}, token expired: {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 return False
print(f'Time is: {now}, token expires: {expires}')
return True
c.JupyterHub.authenticator_class = NextcloudOAuthenticator c.JupyterHub.authenticator_class = NextcloudOAuthenticator
c.NextcloudOAuthenticator.client_id = os.environ['NEXTCLOUD_CLIENT_ID'] c.NextcloudOAuthenticator.client_id = os.environ['NEXTCLOUD_CLIENT_ID']