I have a running jupyterhub service and I want to interact with the REST API with admin privileges.
The docs suggest I can get a authorisation token like this, where username
is an admin user:
$ jupyterhub token --config=<path-to-config> <username>
f9ed5a19d62d4285bbebe2ded9028baf
However, if I use this token in a request to the API it fails:
>>> t1 = 'f9ed5a19d62d4285bbebe2ded9028baf'
>>> requests.get('http://myjupyterhub/hub/api/users', headers={'Authorization': 'token {}'.format(t1)})
>>> <Response [403]>
I can get a token if I have the user's password but this is inconvenient in my scenario:
>>> r = requests.post('http://myjupyterhub/hub/api/authorizations/token', json={'username': 'myadmin', 'password': myadminpass})
>>> t2 = r.json()['Authentication']
>>> requests.get('http://myjupyterhub/hub/api/users', headers={'Authorization': 'token {}'.format(t2)})
>>> <Response [200]>
Have I misunderstood how jupyterhub token
works?