diff --git a/src/lib/api.ts b/src/lib/api.ts index e680143..a44abf5 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -87,6 +87,7 @@ export interface ApiKeyInfo { last_used_at: string | null; revoked_at: string | null; is_active: boolean; + instance_name: string | null; } export interface AnalyticsSummary { @@ -213,10 +214,10 @@ export const api = { listApiKeys: (apiKey: string) => req<{ keys: ApiKeyInfo[]; total: number }>('/api/keys', { headers: authHeader(apiKey) }), - createApiKey: (apiKey: string, name: string) => - req<{ id: number; name: string; api_key: string; mcp_connection: { url: string; header: string } }>( + createApiKey: (apiKey: string, name: string, instanceName?: string) => + req<{ id: number; name: string; instance_name: string | null; api_key: string; mcp_connection: { url: string; header: string } }>( '/api/keys', - { method: 'POST', headers: authHeader(apiKey), body: JSON.stringify({ name }) }, + { method: 'POST', headers: authHeader(apiKey), body: JSON.stringify({ name, instance_name: instanceName || null }) }, ), revokeApiKey: (apiKey: string, id: number) => diff --git a/src/pages/dashboard/Tokens.tsx b/src/pages/dashboard/Tokens.tsx index 0c16860..c56b221 100644 --- a/src/pages/dashboard/Tokens.tsx +++ b/src/pages/dashboard/Tokens.tsx @@ -4,8 +4,10 @@ import { Plus, Trash2, Key, Copy, Check, AlertTriangle } from 'lucide-react'; export default function Tokens() { const [keys, setKeys] = useState([]); + const [instances, setInstances] = useState([]); const [showForm, setShowForm] = useState(false); const [name, setName] = useState(''); + const [scopedInstance, setScopedInstance] = useState(''); const [loading, setLoading] = useState(false); const [newKey, setNewKey] = useState(null); const [copied, setCopied] = useState(false); @@ -14,6 +16,7 @@ export default function Tokens() { const key = session.getKey(); if (!key) return; api.listApiKeys(key).then((r) => setKeys(r.keys)).catch(console.error); + api.listCredentials(key).then((r) => setInstances(r.instances.map((i) => i.instance_name))).catch(console.error); } useEffect(load, []); @@ -23,9 +26,10 @@ export default function Tokens() { if (!key) return; setLoading(true); try { - const result = await api.createApiKey(key, name || 'Untitled key'); + const result = await api.createApiKey(key, name || 'Untitled key', scopedInstance || undefined); setNewKey(result.api_key); setName(''); + setScopedInstance(''); setShowForm(false); load(); } catch (err) { @@ -60,7 +64,8 @@ export default function Tokens() {

API Tokens

- Create and revoke API keys used to connect MCP clients. + Create and revoke API keys used to connect MCP clients. Each key can be locked + to a single Odoo connection, or left unscoped to access all of them.