I changed the TmpAuthenticator project of Jupyterhub 0.96 and want the request with the token argument, like http://192.168.123.3/research/hub/login?token=246810. the code is below:
from traitlets import Bool
from tornado import gen
from jupyterhub.auth import Authenticator
from jupyterhub.handlers import BaseHandler
from jupyterhub.utils import url_path_join
class TmpAuthenticateHandler(BaseHandler):
"""
Handler for /login
Creates a new user with a random UUID, and auto starts their server
"""
def initialize(self, force_new_server, process_user):
super().initialize()
self.force_new_server = force_new_server
self.process_user = process_user
@gen.coroutine
def get(self):
raw_user = yield self.get_current_user()
# username = str(uuid.uuid4())
# username = self.get_argument("user")
username = self.get_argument("token")
raw_user = self.user_from_username(username)
self.set_login_cookie(raw_user)
user = yield gen.maybe_future(self.process_user(raw_user, self))
self.redirect(self.get_next_url(user))
class TmpAuthenticator(Authenticator):
"""
JupyterHub Authenticator for use with tmpnb.org
When JupyterHub is configured to use this authenticator, visiting the home
page immediately logs the user in with a randomly generated UUID if they
are already not logged in, and spawns a server for them.
"""
auto_login = True
login_service = 'tmp'
force_new_server = Bool(
True,
help="""
Stop the user's server and start a new one when visiting /hub/login
When set to True, users going to /hub/login will *always* get a
new single-user server. When set to False, they'll be
redirected to their current session if one exists.
""",
config=True
)
def process_user(self, user, handler):
"""
Do additional arbitrary things to the created user before spawn.
user is a user object, and handler is a TmpAuthenticateHandler object
Should return the new user object.
This method can be a @tornado.gen.coroutine.
Note: This is primarily for overriding in subclasses
"""
return user
def get_handlers(self, app):
# FIXME: How to do this better?
extra_settings = {
'force_new_server': self.force_new_server,
'process_user': self.process_user
}
return [
('/login', TmpAuthenticateHandler, extra_settings)
]
def login_url(self, base_url):
return url_path_join(base_url, 'login')
If I want add a navigator and the link is the base url + token(which is the request token argument), so that the link could be the request with token. I know it could be done by use jinja which is used by jupyterhub, and I can design the link like “/beta?token={token}”. My question is how i can pass or get the token argument in the handler, and get it in the page.html? Thanks!