peppa/apps/web/app/oauth/register/route.ts
Асель 39367b1d82 PEP-8: remote MCP for ChatGPT with Peppa as OAuth 2.1 server
- 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>
2026-11-12 21:38:09 +05:00

28 lines
943 B
TypeScript

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;