feat(api): add token introspection and self-deletion endpoint (#37995)

Adds a /api/v1/token endpoint that allows tokens to introspect and
delete themselves.
partially fixes: https://github.com/go-gitea/gitea/issues/33583

Assisted-by: Mistral Vibe:mistral-medium-3.5

---------

Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
TheFox0x7
2026-06-14 20:05:18 +02:00
committed by GitHub
parent b8ef6a91e6
commit c6167d1ff5
12 changed files with 437 additions and 69 deletions
+97
View File
@@ -19202,6 +19202,38 @@
}
}
},
"/token": {
"get": {
"produces": [
"application/json"
],
"tags": [
"miscellaneous"
],
"summary": "Get the currently authenticated token",
"operationId": "getCurrentToken",
"responses": {
"200": {
"$ref": "#/responses/CurrentAccessToken"
}
}
},
"delete": {
"produces": [
"application/json"
],
"tags": [
"miscellaneous"
],
"summary": "Delete the currently authenticated token",
"operationId": "deleteCurrentToken",
"responses": {
"204": {
"description": "token deleted"
}
}
}
},
"/topics/search": {
"get": {
"produces": [
@@ -25116,6 +25148,47 @@
},
"x-go-package": "gitea.dev/modules/structs"
},
"CurrentAccessToken": {
"type": "object",
"title": "CurrentAccessToken represents the metadata of the currently authenticated token.",
"properties": {
"created_at": {
"description": "The timestamp when the token was created",
"type": "string",
"format": "date-time",
"x-go-name": "CreatedAt"
},
"id": {
"description": "The unique identifier of the access token",
"type": "integer",
"format": "int64",
"x-go-name": "ID"
},
"last_used_at": {
"description": "The timestamp when the token was last used",
"type": "string",
"format": "date-time",
"x-go-name": "LastUsedAt"
},
"name": {
"description": "The name of the access token",
"type": "string",
"x-go-name": "Name"
},
"scopes": {
"description": "The scopes granted to this access token",
"type": "array",
"items": {
"type": "string"
},
"x-go-name": "Scopes"
},
"user": {
"$ref": "#/definitions/UserMeta"
}
},
"x-go-package": "gitea.dev/modules/structs"
},
"DeleteEmailOption": {
"description": "DeleteEmailOption options when deleting email addresses",
"type": "object",
@@ -30585,6 +30658,24 @@
},
"x-go-package": "gitea.dev/models/activities"
},
"UserMeta": {
"type": "object",
"title": "UserMeta represents minimal user information for the token owner.",
"properties": {
"id": {
"description": "The unique identifier of the user",
"type": "integer",
"format": "int64",
"x-go-name": "ID"
},
"login": {
"description": "The username of the user",
"type": "string",
"x-go-name": "Login"
}
},
"x-go-package": "gitea.dev/modules/structs"
},
"UserSettings": {
"description": "UserSettings represents user settings",
"type": "object",
@@ -31089,6 +31180,12 @@
}
}
},
"CurrentAccessToken": {
"description": "CurrentAccessToken represents the currently authenticated access token.",
"schema": {
"$ref": "#/definitions/CurrentAccessToken"
}
},
"DeployKey": {
"description": "DeployKey",
"schema": {
+95
View File
@@ -399,6 +399,16 @@
},
"description": "CronList"
},
"CurrentAccessToken": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CurrentAccessToken"
}
}
},
"description": "CurrentAccessToken represents the currently authenticated access token."
},
"DeployKey": {
"content": {
"application/json": {
@@ -4952,6 +4962,47 @@
"type": "object",
"x-go-package": "gitea.dev/modules/structs"
},
"CurrentAccessToken": {
"properties": {
"created_at": {
"description": "The timestamp when the token was created",
"format": "date-time",
"type": "string",
"x-go-name": "CreatedAt"
},
"id": {
"description": "The unique identifier of the access token",
"format": "int64",
"type": "integer",
"x-go-name": "ID"
},
"last_used_at": {
"description": "The timestamp when the token was last used",
"format": "date-time",
"type": "string",
"x-go-name": "LastUsedAt"
},
"name": {
"description": "The name of the access token",
"type": "string",
"x-go-name": "Name"
},
"scopes": {
"description": "The scopes granted to this access token",
"items": {
"type": "string"
},
"type": "array",
"x-go-name": "Scopes"
},
"user": {
"$ref": "#/components/schemas/UserMeta"
}
},
"title": "CurrentAccessToken represents the metadata of the currently authenticated token.",
"type": "object",
"x-go-package": "gitea.dev/modules/structs"
},
"DeleteEmailOption": {
"description": "DeleteEmailOption options when deleting email addresses",
"properties": {
@@ -10454,6 +10505,24 @@
"type": "object",
"x-go-package": "gitea.dev/models/activities"
},
"UserMeta": {
"properties": {
"id": {
"description": "The unique identifier of the user",
"format": "int64",
"type": "integer",
"x-go-name": "ID"
},
"login": {
"description": "The username of the user",
"type": "string",
"x-go-name": "Login"
}
},
"title": "UserMeta represents minimal user information for the token owner.",
"type": "object",
"x-go-package": "gitea.dev/modules/structs"
},
"UserSettings": {
"description": "UserSettings represents user settings",
"properties": {
@@ -31385,6 +31454,32 @@
]
}
},
"/token": {
"delete": {
"operationId": "deleteCurrentToken",
"responses": {
"204": {
"description": "token deleted"
}
},
"summary": "Delete the currently authenticated token",
"tags": [
"miscellaneous"
]
},
"get": {
"operationId": "getCurrentToken",
"responses": {
"200": {
"$ref": "#/components/responses/CurrentAccessToken"
}
},
"summary": "Get the currently authenticated token",
"tags": [
"miscellaneous"
]
}
},
"/topics/search": {
"get": {
"operationId": "topicSearch",