add token_id to self model

This commit is contained in:
Min RK
2024-04-17 09:27:31 +02:00
parent 7ca2105b80
commit c94dcc435c
3 changed files with 14 additions and 0 deletions

View File

@@ -1774,6 +1774,16 @@ components:
example: example:
- "read:users" - "read:users"
- "access:servers!user=name" - "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: Group:
type: object type: object
properties: properties:

View File

@@ -63,10 +63,13 @@ class SelfAPIHandler(APIHandler):
# add session_id associated with token # add session_id associated with token
# added in 2.0 # added in 2.0
# token_id added in 5.0
token = self.get_token() token = self.get_token()
if token: if token:
model["token_id"] = token.api_id
model["session_id"] = token.session_id model["session_id"] = token.session_id
else: else:
model["token_id"] = None
model["session_id"] = None model["session_id"] = None
# add scopes to identify model, # add scopes to identify model,

View File

@@ -600,6 +600,7 @@ async def test_get_self(app):
r.raise_for_status() r.raise_for_status()
model = r.json() model = r.json()
assert model['name'] == u.name assert model['name'] == u.name
assert model["token_id"] == oauth_token.api_id
# invalid auth gets 403 # invalid auth gets 403
r = await api_request( r = await api_request(