I am using JupyterHub with custom authenticator.
It sets auth_state with access token, which then can be copied into environment inside pre_spawn_start
method like in the example:
class MyAuthenticator(Authenticator):
@gen.coroutine
def authenticate(self, handler, data=None):
username = yield identify_user(handler, data)
upstream_token = yield token_for_user(username)
return {
'name': username,
'auth_state': {
'upstream_token': upstream_token,
},
}
@gen.coroutine
def pre_spawn_start(self, user, spawner):
"""Pass upstream_token to spawner via environment variable"""
auth_state = yield user.get_auth_state()
if not auth_state:
# auth_state not enabled
return
spawner.environment['UPSTREAM_TOKEN'] = auth_state['upstream_token']
However, it happens only once per user. If I logout and login again, the pre_spawn_start
is not called again and old token is still present in the environment variable.
Is it possible to access user.get_auth_state()
directly from the notebook so I can be sure to use the current token, rather then previously set and stored in the environment?
Otherwise, is it possible to force spawner stop on logout so the subsequent login will trigger the pre_spawn_start
?