mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-10 19:43:01 +00:00
Merge pull request #2555 from rcthomas/auth-state-to-spawner
Add Spawner.auth_state_hook
This commit is contained in:
@@ -67,6 +67,9 @@ class HomeHandler(BaseHandler):
|
||||
else:
|
||||
url = url_path_join(self.hub.base_url, 'spawn', user.escaped_name)
|
||||
|
||||
auth_state = await user.get_auth_state()
|
||||
user.spawner.run_auth_state_hook(auth_state)
|
||||
|
||||
html = self.render_template(
|
||||
'home.html',
|
||||
user=user,
|
||||
|
@@ -628,6 +628,24 @@ class Spawner(LoggingConfigurable):
|
||||
"""
|
||||
).tag(config=True)
|
||||
|
||||
auth_state_hook = Any(
|
||||
help="""
|
||||
An optional hook function that you can implement to pass `auth_state`
|
||||
to the spawner after it has been initialized but before it starts.
|
||||
The `auth_state` dictionary may be set by the `.authenticate()`
|
||||
method of the authenticator. This hook enables you to pass some
|
||||
or all of that information to your spawner.
|
||||
|
||||
Example::
|
||||
|
||||
def userdata_hook(spawner, auth_state):
|
||||
spawner.userdata = auth_state["userdata"]
|
||||
|
||||
c.Spawner.auth_state_hook = userdata_hook
|
||||
|
||||
"""
|
||||
).tag(config=True)
|
||||
|
||||
def load_state(self, state):
|
||||
"""Restore state of spawner from database.
|
||||
|
||||
@@ -954,6 +972,14 @@ class Spawner(LoggingConfigurable):
|
||||
except Exception:
|
||||
self.log.exception("post_stop_hook failed with exception: %s", self)
|
||||
|
||||
def run_auth_state_hook(self, auth_state):
|
||||
"""Run the auth_state_hook if defined"""
|
||||
if self.auth_state_hook is not None:
|
||||
try:
|
||||
return self.auth_state_hook(self, auth_state)
|
||||
except Exception:
|
||||
self.log.exception("auth_stop_hook failed with exception: %s", self)
|
||||
|
||||
@property
|
||||
def _progress_url(self):
|
||||
return self.user.progress_url(self.name)
|
||||
|
Reference in New Issue
Block a user