Compare commits
No commits in common. "c143d96fab487f6c5cd533a01324ecc0d3a1e558" and "913980a02761ff5e6d318ece722228526da8da80" have entirely different histories.
c143d96fab
...
913980a027
|
@ -15,28 +15,25 @@ hub:
|
||||||
from oauthenticator.generic import GenericOAuthenticator
|
from oauthenticator.generic import GenericOAuthenticator
|
||||||
def post_auth_hook(authenticator, handler, authentication):
|
def post_auth_hook(authenticator, handler, authentication):
|
||||||
user = authentication['auth_state']['oauth_user']['ocs']['data']['id']
|
user = authentication['auth_state']['oauth_user']['ocs']['data']['id']
|
||||||
authentication['auth_state']['token_expires'] = time.time() + auth_state['token_response']['expires_in']
|
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
|
return authentication
|
||||||
class NextcloudOAuthenticator(GenericOAuthenticator):
|
class NextcloudOAuthenticator(GenericOAuthenticator):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.user_dict = {}
|
self.user_dict = {}
|
||||||
|
|
||||||
async def pre_spawn_start(self, user, spawner):
|
def pre_spawn_start(self, user, spawner):
|
||||||
super().pre_spawn_start(user, spawner)
|
super().pre_spawn_start(user, spawner)
|
||||||
auth_state = await user.get_auth_state()
|
access_token = self.user_dict[user.name]['access_token']
|
||||||
if not auth_state:
|
|
||||||
return
|
|
||||||
access_token = auth_state['access_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):
|
||||||
auth_state = await user.get_auth_state()
|
try:
|
||||||
if not auth_state:
|
access_token = self.user_dict[user.name]['access_token']
|
||||||
return False
|
refresh_token = self.user_dict[user.name]['refresh_token']
|
||||||
access_token = auth_state['access_token']
|
token_response = self.user_dict[user.name]['token_response']
|
||||||
refresh_token = auth_state['refresh_token']
|
|
||||||
token_response = name]['token_response']
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
expires = self.user_dict[user.name]['token_expires']
|
expires = self.user_dict[user.name]['token_expires']
|
||||||
if now >= expires:
|
if now >= expires:
|
||||||
|
@ -45,7 +42,6 @@ hub:
|
||||||
print(f'Time is: {now}, token expires: {expires}')
|
print(f'Time is: {now}, token expires: {expires}')
|
||||||
return True
|
return True
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print(f'No auth_state available for user: {user.name}')
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
c.JupyterHub.authenticator_class = NextcloudOAuthenticator
|
c.JupyterHub.authenticator_class = NextcloudOAuthenticator
|
||||||
|
@ -66,11 +62,6 @@ hub:
|
||||||
extraEnv:
|
extraEnv:
|
||||||
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:
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: jupyterhub-secrets
|
|
||||||
key: crypt-key
|
|
||||||
NEXTCLOUD_CLIENT_ID:
|
NEXTCLOUD_CLIENT_ID:
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
|
|
Loading…
Reference in a new issue