Create and Retrieve User Token by Hub Provider(Admin)

Hi,
We host JupyterHub on Kubernetes for our users. My task, where I would be grateful for your help, is:

  • To create a API token automatically for the user when they first login to our system(using Keycloak as the authentication service)
  • Retrieve the token if it already exists. We have a python library which the user imports and which will try to retrieve the token if possible.

I use the token to find the notebook path where the user is right now, so I can convert his notebook to python code programmatically. We have a feature where we take the notebook code and deploy it automatically on our servers.

For that I need the token. How do I go about doing this?