This commit is contained in:
Micke Nordin 2024-01-12 14:09:43 +01:00
parent 2cc5b2c9e1
commit b6a79287d0
Signed by untrusted user: Micke
GPG key ID: 0DA0A7A5708FE257

View file

@ -12,24 +12,20 @@ hub:
extraConfig:
oauthCode: |
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']
authenticator.user_dict[user] = auth_state
return authentication
class NextcloudOAuthenticator(GenericOAuthenticator):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user_dict = {}
self.user_dict = {}
def pre_spawn_start(self, user, spawner):
super().pre_spawn_start(user, spawner)
access_token = self.user_dict[user.name]['access_token']
# refresh_token = self.user_dict[user.name]['refresh_token']
spawner.environment['NEXTCLOUD_ACCESS_TOKEN'] = access_token
c.JupyterHub.authenticator_class = NextcloudOAuthenticator
c.NextcloudOAuthenticator.client_id = os.environ['NEXTCLOUD_CLIENT_ID']
c.NextcloudOAuthenticator.client_secret = os.environ['NEXTCLOUD_CLIENT_SECRET']