feat: scope API MCP OAuth by principal

This commit is contained in:
wizardchen
2026-06-30 09:21:49 +08:00
committed by lyingbug
parent 77e4f93e3e
commit cb99736d72
39 changed files with 1566 additions and 108 deletions
+45
View File
@@ -17,6 +17,22 @@ export interface TenantInfo {
updated_at: string
}
export type APIPrincipalMode = 'tenant' | 'direct_header' | 'signed_token'
export interface APIPrincipalConfig {
mode: APIPrincipalMode
direct_header_name: string
signed_token_header_name: string
has_hmac_secret: boolean
}
export interface UpdateAPIPrincipalConfigPayload {
mode: APIPrincipalMode
direct_header_name?: string
signed_token_header_name?: string
hmac_secret?: string
}
// 搜索租户参数
export interface SearchTenantsParams {
keyword?: string
@@ -70,6 +86,35 @@ export async function resetTenantApiKey(
}
}
export async function getAPIPrincipalConfig(
tenantId: number,
): Promise<{ success: boolean; data?: APIPrincipalConfig; message?: string }> {
try {
const response = await get(`/api/v1/tenants/${tenantId}/api-principal-config`)
return response as unknown as { success: boolean; data?: APIPrincipalConfig; message?: string }
} catch (error: any) {
return {
success: false,
message: error.message || t('error.tenant.getApiPrincipalConfigFailed'),
}
}
}
export async function updateAPIPrincipalConfig(
tenantId: number,
payload: UpdateAPIPrincipalConfigPayload,
): Promise<{ success: boolean; data?: APIPrincipalConfig; message?: string }> {
try {
const response = await put(`/api/v1/tenants/${tenantId}/api-principal-config`, payload)
return response as unknown as { success: boolean; data?: APIPrincipalConfig; message?: string }
} catch (error: any) {
return {
success: false,
message: error.message || t('error.tenant.updateApiPrincipalConfigFailed'),
}
}
}
/**
* 更新租户信息(目前暴露名称、描述两个字段的编辑入口)。
* 后端 `PUT /tenants/:id` 用指针字段区分"未传"和"显式空串",未传的列不会