Cleaner debug
This commit is contained in:
parent
a2aa3d06f4
commit
e92dd6bd10
|
@ -12,6 +12,7 @@ hub:
|
|||
extraConfig:
|
||||
oauthCode: |
|
||||
import time
|
||||
from datetime import datetime
|
||||
from oauthenticator.generic import GenericOAuthenticator
|
||||
|
||||
def post_auth_hook(authenticator, handler, authentication):
|
||||
|
@ -35,19 +36,25 @@ hub:
|
|||
spawner.environment['NEXTCLOUD_ACCESS_TOKEN'] = access_token
|
||||
|
||||
async def refresh_user(self, user, handler=None):
|
||||
debug = 'NEXTCLOUD_DEBUG_OAUTH' in os.environ
|
||||
auth_state = await user.get_auth_state()
|
||||
if not auth_state:
|
||||
print(f'auth_state missing for {user}')
|
||||
if debug:
|
||||
print(f'auth_state missing for {user}')
|
||||
return False
|
||||
access_token = auth_state['access_token']
|
||||
refresh_token = auth_state['refresh_token']
|
||||
token_response = auth_state['token_response']
|
||||
now = time.time()
|
||||
now_hr = datetime.fromtimestamp(now)
|
||||
expires = auth_state['token_expires']
|
||||
expires_hr = datetime.fromtimestamp(expires)
|
||||
if now >= expires:
|
||||
print(f'Time is: {now}, token expired: {expires}')
|
||||
if debug:
|
||||
print(f'Time is: {now_hr}, token expired: {expires_hr}')
|
||||
return False
|
||||
print(f'Time is: {now}, token expires: {expires}')
|
||||
if debug:
|
||||
print(f'Time is: {now_hr}, token expires: {expires_hr}')
|
||||
return True
|
||||
|
||||
c.JupyterHub.authenticator_class = NextcloudOAuthenticator
|
||||
|
@ -66,6 +73,7 @@ hub:
|
|||
c.NextcloudOAuthenticator.post_auth_hook = post_auth_hook
|
||||
|
||||
extraEnv:
|
||||
NEXTCLOUD_DEBUG_OAUTH: "yes"
|
||||
NEXTCLOUD_HOST: sunet.drive.test.sunet.se
|
||||
JUPYTER_HOST: jupyter.drive.test.sunet.se
|
||||
JUPYTERHUB_CRYPT_KEY:
|
||||
|
|
Loading…
Reference in a new issue