def _hub_authenticator_default(self): auth = JupyterHubAuth(parent=self) auth.login_url = '/hub/login' auth.api_url = '{}/hub/api'.format(self.hubapi_base_url) auth.api_token = self.hubapi_token auth.cookie_name = self.hubapi_cookie return auth
def get_access_token(): # Helps getting the correct ssl configs hub = HubAuth() response = requests.get( os.environ['JUPYTERHUB_HANDLER_CUSTOM_AUTH_URL'], headers={'Authorization': 'token %s' % hub.api_token}, cert=(hub.certfile, hub.keyfile), verify=hub.client_ca, allow_redirects=False) if response.status_code == 200: return response.json()['access_token'] else: raise AuthError
def main(argv=None): port = random_port() hub_auth = HubAuth() hub_auth.client_ca = os.environ.get('JUPYTERHUB_SSL_CLIENT_CA', '') hub_auth.certfile = os.environ.get('JUPYTERHUB_SSL_CERTFILE', '') hub_auth.keyfile = os.environ.get('JUPYTERHUB_SSL_KEYFILE', '') hub_auth._api_request(method='POST', url=url_path_join(hub_auth.api_url, 'batchspawner'), json={'port': port}) cmd_path = which(sys.argv[1]) sys.argv = sys.argv[1:] + ['--port={}'.format(port)] run_path(cmd_path, run_name="__main__")
def update_tokens(): # Helps getting the correct ssl configs hub = HubAuth() response = requests.get( os.environ['JUPYTERHUB_HANDLER_CUSTOM_AUTH_URL'], headers={'Authorization': 'token %s' % hub.api_token}, cert=(hub.certfile, hub.keyfile), verify=hub.client_ca, allow_redirects=False) if response.status_code == 200: SparkContext._active_spark_context._conf.set( "spark.ssb.access", response.json()['access_token']) else: raise AuthError
def main(): # FIXME: remove when we can declare routes in Hub config add_route() hub_auth = HubAuth( cookie_name='jupyter-hub-token', api_token=os.environ['WHOAMI_HUB_API_TOKEN'], login_url='http://127.0.0.1:8000/hub/login', ) app = Application([ (r"/hub/whoami", WhoAmIHandler, dict(hub_auth=hub_auth)), ], login_url=hub_auth.login_url) http_server = HTTPServer(app) http_server.listen(9999) IOLoop.current().start()
def main(argv=None): port = random_port() hub_auth = HubAuth() hub_auth.client_ca = os.environ.get("JUPYTERHUB_SSL_CLIENT_CA", "") hub_auth.certfile = os.environ.get("JUPYTERHUB_SSL_CERTFILE", "") hub_auth.keyfile = os.environ.get("JUPYTERHUB_SSL_KEYFILE", "") hub_auth._api_request( method="POST", url=url_path_join(hub_auth.api_url, "batchspawner"), json={"port": port}, ) cmd_path = which(sys.argv[1]) sys.argv = sys.argv[1:] + ["--port={}".format(port)] run_path(cmd_path, run_name="__main__")
whoami service authentication with the Hub """ from functools import wraps import json import os from urllib.parse import quote from flask import Flask, redirect, request, Response from jupyterhub.services.auth import HubAuth prefix = os.environ.get('JUPYTERHUB_SERVICE_PREFIX', '/') auth = HubAuth( api_token=os.environ['JUPYTERHUB_API_TOKEN'], cache_max_age=60, ) app = Flask(__name__) def authenticated(f): """Decorator for authenticating with the Hub""" @wraps(f) def decorated(*args, **kwargs): cookie = request.cookies.get(auth.cookie_name) if cookie: user = auth.user_for_cookie(cookie) else: user = None if user:
def _hub_authenticator_default(self): auth = JupyterHubAuth(parent=self) auth.api_url = self.jupyterhub_api_url auth.api_token = self.jupyterhub_api_token return auth
def init_hub_auth(self): """Initialize hub authentication""" self.hub_auth = HubAuth()