Add expiration check

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

View file

@ -11,10 +11,12 @@ hub:
storageClassName: csi-sc-cinderplugin
extraConfig:
oauthCode: |
import time
from oauthenticator.generic import GenericOAuthenticator
def post_auth_hook(authenticator, handler, authentication):
user = authentication['auth_state']['oauth_user']['ocs']['data']['id']
auth_state = authentication['auth_state']
auth_state['token_expires'] = time.time() + auth_state['token_response']['expires_in']
authenticator.user_dict[user] = auth_state
return authentication
class NextcloudOAuthenticator(GenericOAuthenticator):
@ -31,7 +33,12 @@ hub:
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']
print(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
c.JupyterHub.authenticator_class = NextcloudOAuthenticator