feat: add Vertex AI authentication support for provider API keys

- Add auth_type field to ProviderAPIKey model (api_key or vertex_ai)
- Implement Vertex AI OAuth token generation with service account
- Update transport layer to handle Vertex AI authentication
- Add Vertex AI endpoint URL generation in request builder
- Update frontend KeyFormDialog to support auth_type selection
- Add migration for auth_type column in provider_api_keys table
This commit is contained in:
fawney19
2026-01-30 02:43:50 +08:00
parent 3e75bc8964
commit 32b293ef3e
16 changed files with 956 additions and 65 deletions
@@ -208,7 +208,7 @@
<span class="text-sm font-medium truncate">{{ key.name || '未命名密钥' }}</span>
<div class="flex items-center gap-1">
<span class="text-[11px] font-mono text-muted-foreground">
{{ key.api_key_masked }}
{{ key.auth_type === 'vertex_ai' ? 'Vertex AI' : key.api_key_masked }}
</span>
<Button
variant="ghost"
@@ -743,7 +743,7 @@ function handleKeyPermissions(key: EndpointAPIKey) {
keyPermissionsDialogOpen.value = true
}
// 复制完整密钥
// 复制完整密钥或认证配置
async function copyFullKey(key: EndpointAPIKey) {
const cached = revealedKeys.value.get(key.id)
if (cached) {
@@ -754,8 +754,20 @@ async function copyFullKey(key: EndpointAPIKey) {
// 否则先获取再复制
try {
const result = await revealEndpointKey(key.id)
revealedKeys.value.set(key.id, result.api_key)
copyToClipboard(result.api_key)
let textToCopy: string
if (result.auth_type === 'vertex_ai' && result.auth_config) {
// Vertex AI 类型:复制 auth_config JSON
textToCopy = typeof result.auth_config === 'string'
? result.auth_config
: JSON.stringify(result.auth_config, null, 2)
} else {
// API Key 类型:复制 api_key
textToCopy = result.api_key || ''
}
revealedKeys.value.set(key.id, textToCopy)
copyToClipboard(textToCopy)
} catch (err: any) {
showError(err.response?.data?.detail || '获取密钥失败', '错误')
}