import { OAuthError, registerClient } from "@peppa/core"; import { db } from "@/lib/db"; import { json, preflight } from "@/lib/oauth"; /** RFC 7591 dynamic client registration. */ export async function POST(req: Request) { const body = (await req.json().catch(() => ({}))) as { client_name?: string; redirect_uris?: unknown }; try { const c = await registerClient(db, body.client_name, body.redirect_uris); return json( { client_id: c.id, client_name: c.name, redirect_uris: c.redirectUris, token_endpoint_auth_method: "none", grant_types: ["authorization_code", "refresh_token"], response_types: ["code"], client_id_issued_at: Math.floor(c.createdAt.getTime() / 1000), }, 201, ); } catch (e) { if (e instanceof OAuthError) return json({ error: e.error, error_description: e.message }, 400); throw e; } } export const OPTIONS = preflight;