Skip to Content
QMD Search SDKAuthentifizierung

Authentifizierung

Der Standalone-Server unterstuetzt optionale Authentifizierung ueber ein Plugin-System. Zwei Plugins sind built-in.

Env-Auth (API-Key)

Prueft den API-Key gegen eine Umgebungsvariable:

import { createEnvAuth } from '@processcube-io/qmd-search/auth/env-auth'; await startServer(store, { auth: createEnvAuth(), // Liest QMD_API_KEY aus der Umgebung });

Konfiguration

createEnvAuth({ headerName: 'X-API-Key', // Default envVar: 'QMD_API_KEY', // Default apiKey: 'direct-key', // Alternativ: Key direkt uebergeben });

Wenn kein Key konfiguriert ist (weder Env-Var noch direkt), werden alle Requests durchgelassen.

Odoo-Auth (REST + Cache)

Validiert API-Keys gegen einen Odoo-REST-Endpoint mit Cache:

import { createOdooAuth } from '@processcube-io/qmd-search/auth/odoo-auth'; await startServer(store, { auth: createOdooAuth({ odooBaseUrl: 'https://odoo.example.com', cacheTtlMs: 300_000, // 5 Minuten Cache }), });

Ablauf

  1. Client sendet X-API-Key Header
  2. Plugin prueft Cache → bei Hit: sofortige Antwort
  3. Bei Cache-Miss: REST-Call an Odoo (POST /api/validate-key)
  4. Odoo antwortet mit { valid, customerId, scopes }
  5. Ergebnis wird gecacht

Konfiguration

OptionDefaultBeschreibung
odooBaseUrl(Pflicht)Odoo-Basis-URL
validateEndpoint/api/validate-keyValidierungs-Endpoint
headerNameX-API-KeyHTTP-Header-Name
cacheTtlMs300000 (5 Min.)Cache-Lebensdauer
maxCacheSize1000Max. Cache-Eintraege

Eigenes Auth-Plugin

import type { AuthPlugin, AuthResult } from '@processcube-io/qmd-search'; const myAuth: AuthPlugin = { name: 'custom', async resolve(req: Request): Promise<AuthResult> { const token = req.headers.get('authorization'); // Eigene Validierungslogik return { valid: true, customerId: 'user-123' }; }, }; await startServer(store, { auth: myAuth });

Health-Endpoint

Der /health-Endpoint ist immer ohne Auth erreichbar — wichtig fuer Kubernetes Liveness/Readiness Probes.