wulf-pulse/lib/utils/openclaw-auth.ts
lorentz 5be7b22953 feat: OpenClaw external agent sync API at /api/openclaw/*
- API key auth via x-openclaw-key header (OPENCLAW_API_KEY env var)
- GET  /api/openclaw/sync/status
- POST /api/openclaw/sync/autotask/incremental
- POST /api/openclaw/sync/autotask/full
- POST /api/openclaw/sync/autotask/entity   { entities: [...] }
- POST /api/openclaw/sync/datto-rmm          { syncType: full|incremental }
- POST /api/openclaw/sync/sentinelone
- POST /api/openclaw/sync/veeam              { syncType: full|incremental }
- POST /api/openclaw/sync/zoom
- POST /api/openclaw/sync/engagement
- POST /api/openclaw/sync/qbo                { syncType: full|incremental }
- POST /api/openclaw/sync/zabbix
- POST /api/openclaw/sync/itglue
All routes bypass Better Auth middleware, delegate to existing sync services
2026-03-17 23:26:44 -04:00

22 lines
706 B
TypeScript

import { NextRequest, NextResponse } from 'next/server';
/**
* Validate the OpenClaw API key from the request header.
* Returns a 401 NextResponse if invalid, or null if valid.
*/
export function validateOpenClawKey(request: NextRequest): NextResponse | null {
const expectedKey = process.env.OPENCLAW_API_KEY;
if (!expectedKey) {
console.error('[OpenClaw] OPENCLAW_API_KEY is not set');
return NextResponse.json({ error: 'OpenClaw API not configured' }, { status: 500 });
}
const providedKey = request.headers.get('x-openclaw-key');
if (!providedKey || providedKey !== expectedKey) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
return null;
}