Compare commits

..

No commits in common. "fbc276d175fa635a36f1c7919719fe6ab92ddf35" and "a16ec5a22754d7243e17bb4cd8ebef7cdb51e890" have entirely different histories.

View file

@ -13,27 +13,19 @@ hub:
oauthCode: | oauthCode: |
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']
auth_state = authentication['auth_state'] auth_state = authentication['auth_state']
authenticator.user_dict[user] = auth_state 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 = {}
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)
access_token = self.user_dict[user.name]['access_token'] access_token = self.user_dict[user.name]['access_token']
spawner.environment['NEXTCLOUD_ACCESS_TOKEN'] = access_token # refresh_token = self.user_dict[user.name]['refresh_token']
spawner.environment['NEXTCLOUD_ACCESS_TOKEN'] = access_token
async def refresh_user(self, user, handler=None):
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)
return True
c.JupyterHub.authenticator_class = NextcloudOAuthenticator c.JupyterHub.authenticator_class = NextcloudOAuthenticator
c.NextcloudOAuthenticator.client_id = os.environ['NEXTCLOUD_CLIENT_ID'] c.NextcloudOAuthenticator.client_id = os.environ['NEXTCLOUD_CLIENT_ID']
c.NextcloudOAuthenticator.client_secret = os.environ['NEXTCLOUD_CLIENT_SECRET'] c.NextcloudOAuthenticator.client_secret = os.environ['NEXTCLOUD_CLIENT_SECRET']