fix(mcp): coordinate OAuth token refresh and authorization polling

Prevent concurrent refresh-token rotation across instances, distinguish
expired-but-refreshable tokens from active authorization, and bind OAuth
popup polling to a per-attempt ID so stale tokens cannot satisfy new consent.
This commit is contained in:
wizardchen
2026-07-23 15:33:20 +08:00
committed by lyingbug
parent c74b0caa35
commit 8ae82573ab
31 changed files with 1418 additions and 109 deletions
+34 -9
View File
@@ -4119,10 +4119,16 @@ const docTemplate = `{
},
{
"type": "integer",
"description": "标签ID筛选(seq_id)",
"description": "标签ID筛选(seq_id),兼容旧版单标签",
"name": "tag_id",
"in": "query"
},
{
"type": "string",
"description": "标签UUID筛选,逗号分隔(OR语义)",
"name": "tag_ids",
"in": "query"
},
{
"type": "string",
"description": "关键词搜索",
@@ -4285,12 +4291,13 @@ const docTemplate = `{
"ApiKeyAuth": []
}
],
"description": "将所有FAQ条目导出为CSV文件",
"description": "将所有FAQ条目导出为 CSV(默认)或 JSON。?format=json 返回与 FAQEntryPayload 结构兼容的数组。",
"consumes": [
"application/json"
],
"produces": [
"text/csv"
"text/csv",
"application/json"
],
"tags": [
"FAQ管理"
@@ -4303,11 +4310,17 @@ const docTemplate = `{
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "导出格式:csv(默认)或 json",
"name": "format",
"in": "query"
}
],
"responses": {
"200": {
"description": "CSV文件",
"description": "导出文件",
"schema": {
"type": "file"
}
@@ -8147,7 +8160,7 @@ const docTemplate = `{
],
"responses": {
"200": {
"description": "{authorization_url: string}",
"description": "{authorization_url: string, authorization_attempt: string}",
"schema": {
"type": "object",
"additionalProperties": true
@@ -8169,7 +8182,7 @@ const docTemplate = `{
"Bearer": []
}
],
"description": "返回当前用户对指定 MCP 服务是否已完成 OAuth 授权",
"description": "返回当前用户的 OAuth Token 生命周期状态;传 authorization_attempt 时只检查本次授权流程",
"produces": [
"application/json"
],
@@ -8184,11 +8197,17 @@ const docTemplate = `{
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "本次授权尝试 ID;传入后不会接受历史 Token",
"name": "authorization_attempt",
"in": "query"
}
],
"responses": {
"200": {
"description": "{authorized: bool}",
"description": "{authorized: bool, state: string, refresh_available: bool, expires_at?: string}",
"schema": {
"type": "object",
"additionalProperties": true
@@ -14950,7 +14969,10 @@ const docTemplate = `{
"kb.share_added",
"kb.share_permission_changed",
"kb.share_removed",
"wiki.content_changed"
"wiki.content_changed",
"faq.import_started",
"faq.import_completed",
"faq.import_failed"
],
"x-enum-varnames": [
"AuditActionMemberAdded",
@@ -15009,7 +15031,10 @@ const docTemplate = `{
"AuditActionKBShareAdded",
"AuditActionKBSharePermissionChanged",
"AuditActionKBShareRemoved",
"AuditActionWikiContentChanged"
"AuditActionWikiContentChanged",
"AuditActionFAQImportStarted",
"AuditActionFAQImportCompleted",
"AuditActionFAQImportFailed"
]
},
"github_com_Tencent_WeKnora_internal_types.AuditLog": {
+34 -9
View File
@@ -4112,10 +4112,16 @@
},
{
"type": "integer",
"description": "标签ID筛选(seq_id)",
"description": "标签ID筛选(seq_id),兼容旧版单标签",
"name": "tag_id",
"in": "query"
},
{
"type": "string",
"description": "标签UUID筛选,逗号分隔(OR语义)",
"name": "tag_ids",
"in": "query"
},
{
"type": "string",
"description": "关键词搜索",
@@ -4278,12 +4284,13 @@
"ApiKeyAuth": []
}
],
"description": "将所有FAQ条目导出为CSV文件",
"description": "将所有FAQ条目导出为 CSV(默认)或 JSON。?format=json 返回与 FAQEntryPayload 结构兼容的数组。",
"consumes": [
"application/json"
],
"produces": [
"text/csv"
"text/csv",
"application/json"
],
"tags": [
"FAQ管理"
@@ -4296,11 +4303,17 @@
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "导出格式:csv(默认)或 json",
"name": "format",
"in": "query"
}
],
"responses": {
"200": {
"description": "CSV文件",
"description": "导出文件",
"schema": {
"type": "file"
}
@@ -8140,7 +8153,7 @@
],
"responses": {
"200": {
"description": "{authorization_url: string}",
"description": "{authorization_url: string, authorization_attempt: string}",
"schema": {
"type": "object",
"additionalProperties": true
@@ -8162,7 +8175,7 @@
"Bearer": []
}
],
"description": "返回当前用户对指定 MCP 服务是否已完成 OAuth 授权",
"description": "返回当前用户的 OAuth Token 生命周期状态;传 authorization_attempt 时只检查本次授权流程",
"produces": [
"application/json"
],
@@ -8177,11 +8190,17 @@
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "本次授权尝试 ID;传入后不会接受历史 Token",
"name": "authorization_attempt",
"in": "query"
}
],
"responses": {
"200": {
"description": "{authorized: bool}",
"description": "{authorized: bool, state: string, refresh_available: bool, expires_at?: string}",
"schema": {
"type": "object",
"additionalProperties": true
@@ -14943,7 +14962,10 @@
"kb.share_added",
"kb.share_permission_changed",
"kb.share_removed",
"wiki.content_changed"
"wiki.content_changed",
"faq.import_started",
"faq.import_completed",
"faq.import_failed"
],
"x-enum-varnames": [
"AuditActionMemberAdded",
@@ -15002,7 +15024,10 @@
"AuditActionKBShareAdded",
"AuditActionKBSharePermissionChanged",
"AuditActionKBShareRemoved",
"AuditActionWikiContentChanged"
"AuditActionWikiContentChanged",
"AuditActionFAQImportStarted",
"AuditActionFAQImportCompleted",
"AuditActionFAQImportFailed"
]
},
"github_com_Tencent_WeKnora_internal_types.AuditLog": {
+26 -6
View File
@@ -331,6 +331,9 @@ definitions:
- kb.share_permission_changed
- kb.share_removed
- wiki.content_changed
- faq.import_started
- faq.import_completed
- faq.import_failed
type: string
x-enum-varnames:
- AuditActionMemberAdded
@@ -390,6 +393,9 @@ definitions:
- AuditActionKBSharePermissionChanged
- AuditActionKBShareRemoved
- AuditActionWikiContentChanged
- AuditActionFAQImportStarted
- AuditActionFAQImportCompleted
- AuditActionFAQImportFailed
github_com_Tencent_WeKnora_internal_types.AuditLog:
properties:
action:
@@ -8328,10 +8334,14 @@ paths:
in: query
name: page_size
type: integer
- description: 标签ID筛选(seq_id)
- description: 标签ID筛选(seq_id),兼容旧版单标签
in: query
name: tag_id
type: integer
- description: 标签UUID筛选,逗号分隔(OR语义)
in: query
name: tag_ids
type: string
- description: 关键词搜索
in: query
name: keyword
@@ -8525,18 +8535,23 @@ paths:
get:
consumes:
- application/json
description: 将所有FAQ条目导出为CSV文件
description: 将所有FAQ条目导出为 CSV(默认)或 JSON。?format=json 返回与 FAQEntryPayload 结构兼容的数组。
parameters:
- description: 知识库ID
in: path
name: id
required: true
type: string
- description: 导出格式:csv(默认)或 json
in: query
name: format
type: string
produces:
- text/csv
- application/json
responses:
"200":
description: CSV文件
description: 导出文件
schema:
type: file
"400":
@@ -10900,7 +10915,7 @@ paths:
- application/json
responses:
"200":
description: '{authorization_url: string}'
description: '{authorization_url: string, authorization_attempt: string}'
schema:
additionalProperties: true
type: object
@@ -10915,18 +10930,23 @@ paths:
- MCP服务
/mcp-services/{id}/oauth/status:
get:
description: 返回当前用户对指定 MCP 服务是否已完成 OAuth 授权
description: 返回当前用户的 OAuth Token 生命周期状态;传 authorization_attempt 时只检查本次授权流程
parameters:
- description: MCP 服务 ID
in: path
name: id
required: true
type: string
- description: 本次授权尝试 ID;传入后不会接受历史 Token
in: query
name: authorization_attempt
type: string
produces:
- application/json
responses:
"200":
description: '{authorized: bool}'
description: '{authorized: bool, state: string, refresh_available: bool,
expires_at?: string}'
schema:
additionalProperties: true
type: object