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
- Client sendet
X-API-KeyHeader - Plugin prueft Cache → bei Hit: sofortige Antwort
- Bei Cache-Miss: REST-Call an Odoo (
POST /api/validate-key) - Odoo antwortet mit
{ valid, customerId, scopes } - Ergebnis wird gecacht
Konfiguration
| Option | Default | Beschreibung |
|---|---|---|
odooBaseUrl | (Pflicht) | Odoo-Basis-URL |
validateEndpoint | /api/validate-key | Validierungs-Endpoint |
headerName | X-API-Key | HTTP-Header-Name |
cacheTtlMs | 300000 (5 Min.) | Cache-Lebensdauer |
maxCacheSize | 1000 | Max. 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.