This commit is contained in:
Micke Nordin 2024-01-18 12:02:55 +01:00
parent 025ba19299
commit 68bd353fe7
Signed by untrusted user: Micke
GPG key ID: F53C4CC83EDAB3BE

View file

@ -18,9 +18,9 @@ hub:
from datetime import datetime
from oauthenticator.generic import GenericOAuthenticator
token_url = 'https://' + os.environ['NEXTCLOUD_HOST'] + '/index.php/apps/oauth2/api/v1/token'
debug = os.environ.get('NEXTCLOUD_DEBUG_OAUTH', 'false').lower() in ['true', '1', 'yes']
def get_nextcloud_access_token(refresh_token):
debug = 'NEXTCLOUD_DEBUG_OAUTH' in os.environ
client_id = os.environ['NEXTCLOUD_CLIENT_ID']
client_secret = os.environ['NEXTCLOUD_CLIENT_SECRET']
@ -58,7 +58,6 @@ 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:
if debug:
@ -176,9 +175,11 @@ hub:
from tornado.ioloop import IOLoop
from tornado.web import Application, HTTPError, RequestHandler, authenticated
from urllib.parse import urlparse
debug = os.environ.get('NEXTCLOUD_DEBUG_OAUTH', 'false').lower() in ['true', '1', 'yes']
def my_debug(s):
with open("/proc/1/fd/1", "a") as stdout:
print(s, file=stdout)
if debug:
with open("/proc/1/fd/1", "a") as stdout:
print(s, file=stdout)
class RefreshHandler(HubAuthenticated, RequestHandler):
@ -232,11 +233,11 @@ hub:
# Fetch current auth state
user_data = self.api_request('GET', url_path_join('users', user_model['name']))
auth_state = user_data['auth_state']
my_debug(f"DEBUG: {auth_state}")
access_token = auth_state['access_token']
token_expires = auth_state['token_expires']
self.set_header('content-type', 'application/json')
self.write(json.dumps(auth_state, indent=1, sort_keys=True))
self.write(json.dumps({'access_token': access_token, 'token_expires': token_expires}, indent=1, sort_keys=True))
class PingHandler(RequestHandler):
@ -275,7 +276,7 @@ hub:
targetPort: 8082
name: refresh-token
extraEnv:
NEXTCLOUD_DEBUG_OAUTH: "yes"
NEXTCLOUD_DEBUG_OAUTH: "no"
NEXTCLOUD_HOST: sunet.drive.test.sunet.se
JUPYTER_HOST: jupyter.drive.test.sunet.se
JUPYTERHUB_API_KEY: