- OAuth: RFC 8414/9728 metadata, RFC 7591 dynamic registration, authorization code + PKCE S256 with a consent screen after Gitea login, refresh token rotation; tokens and codes stored hashed; revoke in web - /mcp: stateless Streamable HTTP, Bearer → user; PM tools from @peppa/mcp/manager: projects, goals, tasks, create, move (board semantics, starts agents), inbox, answer/accept — owner-scoped - login keeps ?next= through Gitea OAuth; Settings page with MCP URL and connected apps - 5 new tests (53 e2e total, green); verified on prod as a client: DCR → consent → token → MCP over HTTPS → revoke → 401 - OpenSpec: pep-8 archived into spec remote-mcp Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
18 lines
709 B
TypeScript
18 lines
709 B
TypeScript
import { exchangeToken, OAuthError } from "@peppa/core";
|
|
import { db } from "@/lib/db";
|
|
import { json, preflight } from "@/lib/oauth";
|
|
|
|
export async function POST(req: Request) {
|
|
const type = req.headers.get("content-type") ?? "";
|
|
const params: Record<string, string> = type.includes("application/json")
|
|
? ((await req.json().catch(() => ({}))) as Record<string, string>)
|
|
: Object.fromEntries(new URLSearchParams(await req.text()));
|
|
try {
|
|
return json(await exchangeToken(db, params));
|
|
} catch (e) {
|
|
if (e instanceof OAuthError) return json({ error: e.error, error_description: e.message }, e.error === "invalid_client" ? 401 : 400);
|
|
throw e;
|
|
}
|
|
}
|
|
export const OPTIONS = preflight;
|