#!/usr/bin/env python # coding: utf-8 # All user servers have access to a JUPYTERHUB_API_TOKEN, # which allows access to the JupyterHub API. # In[1]: import os for key, value in sorted(os.environ.items()): if key.startswith('JUPYTERHUB_'): print(f"{key}: {value}") # Make a POST request to /hub/api/onetimetoken authorized with our JUPYTERHUB_API_TOKEN # in order to create a shareable link. # In[2]: import os import requests from urllib.parse import urlparse from jupyterhub.utils import url_path_join api_token = os.environ['JUPYTERHUB_API_TOKEN'] api_url = os.environ['JUPYTERHUB_API_URL'] base_url = os.environ['JUPYTERHUB_BASE_URL'] onetime_url = url_path_join(api_url, "onetimetoken") r = requests.post(onetime_url, headers={'Authorization': f'token {api_token}'}) r.raise_for_status() reply = r.json() reply # Now we can make an HTML link that can be shared, # to grant one-time logins to someone with the link: # In[8]: from IPython.display import HTML HTML(f"This is your one-time link") # Copy that link and share it to allow login as you with one-time tokens. # The link will only work once.