Compare commits

..

No commits in common. "755b16530246e53980b9c3ccfd5a1abe81c9df3c" and "a2aa3d06f440a113d5b2f317befdf088bd123815" have entirely different histories.

View file

@ -12,7 +12,6 @@ hub:
extraConfig: extraConfig:
oauthCode: | oauthCode: |
import time import time
from datetime import datetime
from oauthenticator.generic import GenericOAuthenticator from oauthenticator.generic import GenericOAuthenticator
def post_auth_hook(authenticator, handler, authentication): def post_auth_hook(authenticator, handler, authentication):
@ -33,29 +32,22 @@ hub:
if not auth_state: if not auth_state:
return return
access_token = auth_state['access_token'] access_token = auth_state['access_token']
access_token = auth_state['refresh_token']
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):
debug = 'NEXTCLOUD_DEBUG_OAUTH' in os.environ
auth_state = await user.get_auth_state() auth_state = await user.get_auth_state()
if not auth_state: if not auth_state:
if debug: print(f'auth_state missing for {user}')
print(f'auth_state missing for {user}')
return False return False
access_token = auth_state['access_token'] access_token = auth_state['access_token']
refresh_token = auth_state['refresh_token'] refresh_token = auth_state['refresh_token']
token_response = auth_state['token_response'] token_response = auth_state['token_response']
now = time.time() now = time.time()
now_hr = datetime.fromtimestamp(now)
expires = auth_state['token_expires'] expires = auth_state['token_expires']
expires_hr = datetime.fromtimestamp(expires)
if now >= expires: if now >= expires:
if debug: print(f'Time is: {now}, token expired: {expires}')
print(f'Time is: {now_hr}, token expired: {expires_hr}')
return False return False
if debug: print(f'Time is: {now}, token expires: {expires}')
print(f'Time is: {now_hr}, token expires: {expires_hr}')
return True return True
c.JupyterHub.authenticator_class = NextcloudOAuthenticator c.JupyterHub.authenticator_class = NextcloudOAuthenticator
@ -74,7 +66,6 @@ hub:
c.NextcloudOAuthenticator.post_auth_hook = post_auth_hook c.NextcloudOAuthenticator.post_auth_hook = post_auth_hook
extraEnv: extraEnv:
NEXTCLOUD_DEBUG_OAUTH: "yes"
NEXTCLOUD_HOST: sunet.drive.test.sunet.se NEXTCLOUD_HOST: sunet.drive.test.sunet.se
JUPYTER_HOST: jupyter.drive.test.sunet.se JUPYTER_HOST: jupyter.drive.test.sunet.se
JUPYTERHUB_CRYPT_KEY: JUPYTERHUB_CRYPT_KEY: