Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,14 +1,22 @@
import { Form, useLoaderData } from "react-router";
import type { LoaderFunctionArgs } from "react-router";
import { FeatherAlertTriangle } from "@subframe/core";
import { FeatherEye, FeatherPencil } from "@subframe/core";
import { describeMcpScope, resolveMcpClientIcon } from "@hivegrid/view-models";
import { requireUserId, getUserInfo } from "~/utils/session.server";
import { McpOAuthError, resolveAuthorizeRequest, type McpOAuthAuthorizeRequest } from "~/services/mcp/oauth.server";
import { getTranslations } from "~/locale/i18next.server";
import { loadRequiredWebConfig } from "@hivegrid/config";
import { AuthShell, AuthStatus } from "~/components/auth/AuthShell";
import { ClientIcon } from "~/components/mcp/ClientIcon";
import { Button } from "~/ui/components/Button";
type AuthorizeLabels = {
errorTitle: string;
title: string;
description: string;
scopesHeading: string;
revokeHint: string;
approve: string;
deny: string;
};
@@ -25,10 +33,22 @@ export async function loader({ request }: LoaderFunctionArgs) {
errorTitle: t("mcp.oauth.authorize.errorTitle"),
title: t("mcp.oauth.authorize.title", { appName }),
description: t("mcp.oauth.authorize.description", { clientName: resolved.client.clientName, tenantName: resolved.tenant.name }),
scopesHeading: t("mcp.oauth.authorize.scopesHeading"),
revokeHint: t("mcp.oauth.authorize.revokeHint", { appName }),
approve: t("mcp.oauth.authorize.approve"),
deny: t("mcp.oauth.authorize.deny"),
};
return Response.json({ ...resolved, csrf: userInfo.csrf ?? "", labels });
// Same brand-mark derivation the connect dialog uses, so the client the
// user is about to approve looks the same here as it does afterwards.
const clientIcon = resolveMcpClientIcon(resolved.client.clientName);
// Every requested scope still gets its own row — the consent has to stay
// complete. Each carries a plain-language label where we have one; the raw
// scope stays visible underneath so nothing is paraphrased away.
const scopeRows = resolved.scopes.map((scope) => {
const described = describeMcpScope(scope);
return { ...described, label: described.labelKey ? t(described.labelKey) : null };
});
return Response.json({ ...resolved, csrf: userInfo.csrf ?? "", clientIcon, scopeRows, labels });
} catch (error) {
if (error instanceof McpOAuthError) {
return Response.json(
@@ -40,48 +60,91 @@ export async function loader({ request }: LoaderFunctionArgs) {
}
}
type ScopeRow = { scope: string; labelKey: string | null; label: string | null; write: boolean };
type AuthorizeData = McpOAuthAuthorizeRequest & { csrf: string; clientIcon: string; scopeRows: ScopeRow[]; labels: AuthorizeLabels };
type AuthorizeError = { error: string; errorDescription: string; labels: { errorTitle: string } };
export default function McpOAuthAuthorizeRoute() {
const data = useLoaderData<(McpOAuthAuthorizeRequest & { csrf: string; labels: AuthorizeLabels }) | { error: string; errorDescription: string; labels: { errorTitle: string } }>();
const data = useLoaderData<AuthorizeData | AuthorizeError>();
if ("error" in data) {
return (
<main className="flex min-h-screen items-center justify-center bg-gray-50 px-6 py-12">
<section className="w-full max-w-lg rounded-lg border border-red-200 bg-white p-6 shadow-sm">
<h1 className="text-xl font-semibold text-gray-950">{data.labels.errorTitle}</h1>
<p className="mt-3 text-sm text-gray-700">{data.errorDescription}</p>
</section>
</main>
<AuthStatus
icon={<FeatherAlertTriangle />}
tone="negative"
title={data.labels.errorTitle}
message={data.errorDescription}
dataUiId="ui.mcp.oauth.authorize.error"
/>
);
}
return (
<main className="flex min-h-screen items-center justify-center bg-gray-50 px-6 py-12">
<section className="w-full max-w-lg rounded-lg border border-gray-200 bg-white p-6 shadow-sm">
<h1 className="text-xl font-semibold text-gray-950">{data.labels.title}</h1>
<p className="mt-3 text-sm text-gray-700">{data.labels.description}</p>
<ul className="mt-4 list-disc space-y-1 pl-5 text-sm text-gray-700">
{data.scopes.map((scope) => (
<li key={scope}>{scope}</li>
<AuthShell
title={data.labels.title}
subtitle={data.labels.description}
titleAlign="start"
cardSize="large"
showLogo={true}
dataUiId="ui.mcp.oauth.authorize.page"
>
<div className="border-border-default bg-surface-neutral-secondary flex w-full items-center gap-3 rounded-md border border-solid px-3 py-2.5">
<ClientIcon icon={data.clientIcon} className="h-5 w-5" />
<div className="flex min-w-0 grow flex-col">
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary truncate">{data.client.clientName}</span>
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary truncate">{data.tenant.name}</span>
</div>
</div>
<div className="flex w-full flex-col gap-2">
<span className="text-body-small-semibold-0 font-body-small-semibold-0 text-text-neutral-primary">{data.labels.scopesHeading}</span>
<ul className="flex w-full list-none flex-col gap-1.5 p-0">
{data.scopeRows.map((row) => (
<li
key={row.scope}
className="border-border-default flex w-full items-start gap-2.5 rounded-md border border-solid px-3 py-2"
data-ui-id={`ui.mcp.oauth.authorize.scope.${row.scope}`}
>
<span className={`mt-0.5 flex h-4 w-4 shrink-0 [&>svg]:h-full [&>svg]:w-full ${row.write ? "text-icon-feedback-warning" : "text-icon-neutral-secondary"}`}>
{row.write ? <FeatherPencil /> : <FeatherEye />}
</span>
<div className="flex min-w-0 grow flex-col">
{row.label ? (
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary">{row.label}</span>
) : null}
{/* The raw scope stays on screen even when a label exists: it is
what actually gets granted, and an unlabelled scope must
never look like it was silently dropped. */}
<code className="font-mono text-body-extra-small-regular-0 text-text-neutral-tertiary break-all">{row.scope}</code>
</div>
</li>
))}
</ul>
<Form method="post" action="/oauth/authorize/approve" className="mt-6 flex gap-3">
<input type="hidden" name="csrf" value={data.csrf} />
<input type="hidden" name="response_type" value="code" />
<input type="hidden" name="client_id" value={data.client.clientId} />
<input type="hidden" name="redirect_uri" value={data.redirectUri} />
<input type="hidden" name="scope" value={data.scopes.join(" ")} />
<input type="hidden" name="code_challenge" value={data.codeChallenge} />
<input type="hidden" name="code_challenge_method" value={data.codeChallengeMethod} />
<input type="hidden" name="resource" value={data.resource} />
<input type="hidden" name="tenant" value={data.tenant.id} />
{data.state ? <input type="hidden" name="state" value={data.state} /> : null}
<button name="decision" value="approve" className="rounded-md bg-gray-950 px-4 py-2 text-sm font-semibold text-white">
{data.labels.approve}
</button>
<button name="decision" value="deny" className="rounded-md border border-gray-300 px-4 py-2 text-sm font-semibold text-gray-800">
{data.labels.deny}
</button>
</Form>
</section>
</main>
</div>
<Form method="post" action="/oauth/authorize/approve" className="flex w-full flex-col gap-3">
<input type="hidden" name="csrf" value={data.csrf} />
<input type="hidden" name="response_type" value="code" />
<input type="hidden" name="client_id" value={data.client.clientId} />
<input type="hidden" name="redirect_uri" value={data.redirectUri} />
<input type="hidden" name="scope" value={data.scopes.join(" ")} />
<input type="hidden" name="code_challenge" value={data.codeChallenge} />
<input type="hidden" name="code_challenge_method" value={data.codeChallengeMethod} />
<input type="hidden" name="resource" value={data.resource} />
<input type="hidden" name="tenant" value={data.tenant.id} />
{data.state ? <input type="hidden" name="state" value={data.state} /> : null}
<Button type="submit" name="decision" value="approve" variant="primary" size="large" className="w-full">
{data.labels.approve}
</Button>
{/* `neutral` is remapped to the same solid black as `primary` in
globals.css, so the decline action needs the outlined variant to
read as the secondary choice. */}
<Button type="submit" name="decision" value="deny" variant="secondary" size="large" className="w-full">
{data.labels.deny}
</Button>
</Form>
<p className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary">{data.labels.revokeHint}</p>
</AuthShell>
);
}