Hi.
How to pass custom user attributes from KeyCloak to Jupyter (Notebook/Spawner).
We want to configure all user-individual attributes from KeyCloak, if possible.
Hi.
How to pass custom user attributes from KeyCloak to Jupyter (Notebook/Spawner).
We want to configure all user-individual attributes from KeyCloak, if possible.
You should be able to do this with c.Spawner.pre_spawn_hook:
async def load_auth_info(spawner):
auth_state = await spawner.user.get_auth_state()
# auth_state is a Python dict that will contain info such as the reply from your request to `Authenticator.userdata_url`
set_things_on(spawner, auth_state)...
c.Spawner.pre_spawn_hook = load_auth_info
If you need to perform additional requests to retrieve this info, you may be better off with a custom Authenticator to load this into the auth state, in which case you might use Authenticator.pre_spawn_start
, which is a method on Authenticator instead of a user-provided function.
Authenticator.pre_spawn_start
and Spawner.pre_spawn_hook
are a bit tricky to distinguish (they both run when a spawner is about to start and tend to be used for the same kind of thing). The main difference is that Authenticator.pre_spawn_start is a method on your Authenticator and cannot be overridden by user configuration, whereas pre_spawn_hook
can be registered purely with config without modifying any classes. If your custom Authenticator is defined in config already, there’s really no difference other than access to the authenticator as self
. So the difference is mainly in audience: the Authenticator author vs the deployment admin.
Thanks a bunch. I already found the solution and posted in this forum, but in another thread, I thought this was closed.
Also, you need to enable auth_state which is disabled by default (to my knowledge).
Yes! It is disabled by default because it requires some keys to be set and the sensitive info is not always needed, so not persisted by default.