Jupyterhub API Token: How to get an authenticated token on a running single user server programmatically


What I want is to check user’s groups and read group members programmatically, with scopes I have set in roles.
I don’t know if there is a proper way to do that, and I try to use API to request from the hub. And the problem is where I can get an authenticated API token with full access to the JupyterHub API for this.
I have tried $JUPYTERHUB_API_TOKEN but it doesn’t work.
One way is to get from the web page. But since We want do the checks programmatically and maybe in postStart lifehooks, how can I do it properly?

Thanks for your help.

I may found the solution, and Understanding token scope difference helps a lot.

c.JupyterHub.load_roles = [
   'name': 'server',
   'scopes': ['all'],