diff --git a/docs/source/_static/rest-api.yml b/docs/source/_static/rest-api.yml index 8602e26e..9e3a7a86 100644 --- a/docs/source/_static/rest-api.yml +++ b/docs/source/_static/rest-api.yml @@ -1774,6 +1774,16 @@ components: example: - "read:users" - "access:servers!user=name" + token_id: + type: + - string + - "null" + description: | + The id of the token authorizing the request, if any. + This id can be used to revoke the token via the API. + Null if the request is not authorized with a token. + + Added in 5.0. Group: type: object properties: diff --git a/jupyterhub/apihandlers/users.py b/jupyterhub/apihandlers/users.py index 220901a9..f9cdbdfc 100644 --- a/jupyterhub/apihandlers/users.py +++ b/jupyterhub/apihandlers/users.py @@ -63,10 +63,13 @@ class SelfAPIHandler(APIHandler): # add session_id associated with token # added in 2.0 + # token_id added in 5.0 token = self.get_token() if token: + model["token_id"] = token.api_id model["session_id"] = token.session_id else: + model["token_id"] = None model["session_id"] = None # add scopes to identify model, diff --git a/jupyterhub/tests/test_api.py b/jupyterhub/tests/test_api.py index 77d16861..3ad326df 100644 --- a/jupyterhub/tests/test_api.py +++ b/jupyterhub/tests/test_api.py @@ -600,6 +600,7 @@ async def test_get_self(app): r.raise_for_status() model = r.json() assert model['name'] == u.name + assert model["token_id"] == oauth_token.api_id # invalid auth gets 403 r = await api_request(