- 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>
72 lines
2.8 KiB
TypeScript
72 lines
2.8 KiB
TypeScript
import { checkAuthorizeRequest, OAuthError, type OAuthClient } from "@peppa/core";
|
||
import { redirect } from "next/navigation";
|
||
import { currentUser } from "@/lib/auth";
|
||
import { db } from "@/lib/db";
|
||
import { approve, deny } from "./actions";
|
||
|
||
export const dynamic = "force-dynamic";
|
||
|
||
type Params = Record<string, string | undefined>;
|
||
|
||
/** OAuth consent screen: who asks, what they get, allow / deny. */
|
||
export default async function Authorize({ searchParams }: { searchParams: Promise<Params> }) {
|
||
const p = await searchParams;
|
||
const user = await currentUser();
|
||
if (!user) redirect(`/login?next=${encodeURIComponent(`/oauth/authorize?${new URLSearchParams(p as Record<string, string>)}`)}`);
|
||
let client: OAuthClient | null = null;
|
||
let error: string | null = null;
|
||
try {
|
||
client = await checkAuthorizeRequest(db, {
|
||
clientId: p.client_id ?? "",
|
||
redirectUri: p.redirect_uri ?? "",
|
||
codeChallenge: p.code_challenge ?? "",
|
||
codeChallengeMethod: p.code_challenge_method ?? "",
|
||
responseType: p.response_type ?? "",
|
||
scope: p.scope,
|
||
});
|
||
} catch (e) {
|
||
error = e instanceof OAuthError ? e.message : (e as Error).message;
|
||
}
|
||
const host = p.redirect_uri ? new URL(p.redirect_uri).host : "";
|
||
return (
|
||
<main className="login consent">
|
||
<h1>🐷 Peppa</h1>
|
||
{error || !client ? (
|
||
<p className="flash">Запрос авторизации некорректен: {error}</p>
|
||
) : (
|
||
<>
|
||
<p>
|
||
<b>{client.name}</b> <span className="muted">({host})</span> просит доступ к Пеппе от имени <b>{user.login}</b>.
|
||
</p>
|
||
<ul className="scopes">
|
||
<li>видеть ваши проекты, цели, задачи и вопросы агентов;</li>
|
||
<li>создавать задачи и двигать карточки — перенос в «В работе» запускает агента;</li>
|
||
<li>отвечать на вопросы агентов и принимать ревью.</li>
|
||
</ul>
|
||
<p className="muted">Отозвать доступ можно в «Настройки → Подключённые приложения».</p>
|
||
<div className="row">
|
||
<form action={approve}>
|
||
<Hidden p={p} />
|
||
<button className="primary">Разрешить</button>
|
||
</form>
|
||
<form action={deny}>
|
||
<Hidden p={p} />
|
||
<button>Отклонить</button>
|
||
</form>
|
||
</div>
|
||
</>
|
||
)}
|
||
</main>
|
||
);
|
||
}
|
||
|
||
function Hidden({ p }: { p: Params }) {
|
||
return (
|
||
<>
|
||
{(["client_id", "redirect_uri", "code_challenge", "code_challenge_method", "response_type", "scope", "state"] as const).map((k) => (
|
||
<input key={k} type="hidden" name={k} value={p[k] ?? ""} />
|
||
))}
|
||
</>
|
||
);
|
||
}
|