How to pass access_token from Auth0 to the user's pod?

Hi,

I would like to passe some information to the user’s pod such like the auth_token. I guess it is possible to pass some information with c.KubeSpawner.pre_spawn_hook (and environment variable) but I can’t access to the token. How can I pass that information, please ?

Regards

I have found the solution. Here is what I made :

hub:
  extraConfig:
    oauth.py: |
      from oauthenticator.auth0 import Auth0OAuthenticator
      from tornado import gen
      class CustomAuth0OAuthenticator(Auth0OAuthenticator):
        async def pre_spawn_start(self, user, spawner):
          spawner.log.debug('BEGIN pre_spawn_start')
          auth_state = await user.get_auth_state()
          spawner.environment['ACCESS_TOKEN'] = auth_state['access_token']
          spawner.environment['ID_TOKEN'] = auth_state['id_token']
          spawner.log.debug('END pre_spawn_start')
1 Like

How can I use it? Should it appear in user pod envs after addition only this piece of code or I have to add something else?

Hi,

After that change, the user pod environment should have two new variables (those specified above). You can access them either in a terminal or with python.

Example:

import os
print(os.environ['ACCESS_TOKEN'])
1 Like

@yilas Would you mind sharing more of your helm file, or taking a look at the thread I just made with a similar issue? I’m trying to pass the access_token from the auth_state with a custom authenticator as well