mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
Merge pull request #3105 from appwrite/feat/mcp-consent-narrowing
Consent-time scope narrowing for MCP grants
This commit is contained in:
3 files changed
+738
-12
No files matched your search
@@ -0,0 +1,209 @@
|
||||
import { env } from '$env/dynamic/public';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import {
|
||||
ALL_SCOPE,
|
||||
PROJECT_ALL_SCOPE,
|
||||
ORGANIZATION_ALL_SCOPE,
|
||||
PROJECT_SCOPE_PREFIX,
|
||||
ORGANIZATION_SCOPE_PREFIX,
|
||||
scopeAction,
|
||||
scopeResource,
|
||||
type ConsentScopeModel,
|
||||
type TierScopes
|
||||
} from '$lib/helpers/oauth2-scopes';
|
||||
|
||||
/**
|
||||
* MCP-grant detection and consent-time scope narrowing for the hosted Appwrite
|
||||
* MCP server (granular MCP scopes design).
|
||||
*
|
||||
* The MCP server advertises the authorization server's full scope catalog, so
|
||||
* MCP clients mechanically request *everything*. The consent screen detects
|
||||
* those grants — the grant's RFC 8707 `resources` contains the MCP server's
|
||||
* canonical resource URI — and only then offers a narrowing editor. Because
|
||||
* every granular scope was literally requested, whatever the user narrows to is
|
||||
* a plain subset that the approve endpoint's literal check already accepts.
|
||||
*
|
||||
* The detection signal is self-fulfilling: the resource value becomes the
|
||||
* token's `aud`, and the MCP server hard-rejects foreign audiences, so a lying
|
||||
* client gains nothing by claiming the MCP resource URI.
|
||||
*/
|
||||
|
||||
/** Canonical resource URI of the hosted Appwrite MCP server. */
|
||||
export const DEFAULT_MCP_RESOURCE_URLS = ['https://mcp.appwrite.io/mcp'];
|
||||
|
||||
/** Mirror of the authorization server's `scope` parameter length cap. */
|
||||
export const MAX_SCOPE_PARAM_LENGTH = 8192;
|
||||
|
||||
/** Normalize an RFC 8707 resource URI for comparison: trailing slashes only —
|
||||
* resource indicators are canonical URIs, so anything else compares exactly. */
|
||||
export function normalizeResourceUrl(url: string): string {
|
||||
return url.trim().replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* The MCP resource URIs this console recognizes. Defaults to the hosted MCP;
|
||||
* extendable via the comma-separated `PUBLIC_MCP_RESOURCE_URLS` env var (e.g.
|
||||
* `http://localhost:8000/mcp` for local development).
|
||||
*/
|
||||
export function mcpResourceUrls(raw?: string | null): string[] {
|
||||
const configured = (raw ?? env.PUBLIC_MCP_RESOURCE_URLS ?? '')
|
||||
.split(',')
|
||||
.map(normalizeResourceUrl)
|
||||
.filter((url) => url !== '');
|
||||
return configured.length > 0 ? configured : DEFAULT_MCP_RESOURCE_URLS;
|
||||
}
|
||||
|
||||
/** Whether any of the grant's requested resources is a known MCP resource URI. */
|
||||
export function isMcpResource(resources: string[], urls: string[] = mcpResourceUrls()): boolean {
|
||||
const known = new Set(urls.map(normalizeResourceUrl));
|
||||
return resources.some(
|
||||
(resource) => typeof resource === 'string' && known.has(normalizeResourceUrl(resource))
|
||||
);
|
||||
}
|
||||
|
||||
/** MCP grants (and only MCP grants) get the consent-time narrowing editor. */
|
||||
export function isMcpGrant(grant: Models.Oauth2Grant, urls?: string[]): boolean {
|
||||
return isMcpResource(grant.resources ?? [], urls ?? mcpResourceUrls());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Grant composition — turn the editor's selection into the approve payload */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/** Per-resource editor selection within one tier. Rows absent from the record
|
||||
* default to selected with full requested access. */
|
||||
export interface ResourceSelection {
|
||||
selected: boolean;
|
||||
/** `full` grants every requested action; `read` keeps only `.read`. */
|
||||
level: 'full' | 'read';
|
||||
}
|
||||
|
||||
export type TierSelection = Record<string, ResourceSelection>;
|
||||
|
||||
export interface ComposeInput {
|
||||
model: ConsentScopeModel;
|
||||
project: TierSelection;
|
||||
organization: TierSelection;
|
||||
/** Master read-only toggle — treats every selected resource as `read`. */
|
||||
readOnly: boolean;
|
||||
/** True when the user narrowed the org/project resource pickers. */
|
||||
resourcesNarrowed: boolean;
|
||||
}
|
||||
|
||||
export interface ComposedGrant {
|
||||
/**
|
||||
* The `scope` value for the approve endpoint, or `undefined` to omit it.
|
||||
* Omission means "grant the full literal requested list" — required so the
|
||||
* consent-skip diff stays empty on the next re-authorization.
|
||||
*/
|
||||
scope: string | undefined;
|
||||
/** The user's selection is the full request — nothing was narrowed. */
|
||||
untouched: boolean;
|
||||
/** No non-identity scope remains; Authorize must be disabled. */
|
||||
blocked: boolean;
|
||||
/** A tier was collapsed to its umbrella to fit the scope length cap. */
|
||||
lengthCollapsed: boolean;
|
||||
}
|
||||
|
||||
/** The bare scope tokens (`tables.read`, …) one tier's selection emits. Every
|
||||
* emitted token is one of the tier's requested tokens — never synthesized —
|
||||
* so the result is a literal subset of the request by construction. */
|
||||
function tierEmission(
|
||||
tier: TierScopes,
|
||||
selection: TierSelection,
|
||||
readOnly: boolean
|
||||
): { tokens: string[]; full: boolean } {
|
||||
const tokens: string[] = [];
|
||||
for (const token of tier.scopes) {
|
||||
const resource = scopeResource(token);
|
||||
const action = scopeAction(token);
|
||||
const row = selection[resource] ?? { selected: true, level: 'full' };
|
||||
if (!row.selected) continue;
|
||||
const level = readOnly ? 'read' : row.level;
|
||||
if (level === 'read' && action !== 'read') continue;
|
||||
tokens.push(token);
|
||||
}
|
||||
return { tokens, full: tokens.length === tier.scopes.length };
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose the scope narrowing to send to the approve endpoint.
|
||||
*
|
||||
* - Untouched selection → omit `scope` entirely: the server keeps the full
|
||||
* literal requested list, so re-authorizations skip consent (the diff against
|
||||
* the previously approved scopes stays empty).
|
||||
* - Any narrowing → identity scopes plus the selected granular tokens; a tier
|
||||
* whose requested tokens all survive collapses to its requested umbrella
|
||||
* (`project:all` / `organization:all`). The console-wide `all` is never part
|
||||
* of a narrowed grant — it bypasses RFC 9396 resource restrictions.
|
||||
* - `.write` never implies `.read`: a "Read + Write" row emits both tokens.
|
||||
*/
|
||||
export function composeGrantedScopes(input: ComposeInput): ComposedGrant {
|
||||
const { model, readOnly, resourcesNarrowed } = input;
|
||||
|
||||
const project = tierEmission(model.project, input.project, readOnly);
|
||||
const organization = tierEmission(model.organization, input.organization, readOnly);
|
||||
|
||||
const capabilitiesFull = project.full && organization.full && !readOnly;
|
||||
if (capabilitiesFull && !resourcesNarrowed) {
|
||||
return { scope: undefined, untouched: true, blocked: false, lengthCollapsed: false };
|
||||
}
|
||||
|
||||
// A fully-kept tier collapses to its umbrella (when the umbrella was
|
||||
// requested) — keeps the granted string short and re-consent diffs sane.
|
||||
// Covers the degenerate umbrella-only request (`project:all` with no
|
||||
// granular tokens) too: a full selection keeps the umbrella.
|
||||
const tierScopes = (
|
||||
tier: TierScopes,
|
||||
emission: { tokens: string[]; full: boolean },
|
||||
prefix: string,
|
||||
umbrella: string
|
||||
): string[] => {
|
||||
const requested = tier.all || tier.scopes.length > 0;
|
||||
// Never collapse under read-only: the umbrella grants write, so a tier
|
||||
// whose requested tokens are all `.read` (emission.full despite the
|
||||
// toggle) must still emit the explicit token list.
|
||||
if (requested && emission.full && tier.all && !readOnly) return [umbrella];
|
||||
return emission.tokens.map((token) => prefix + token);
|
||||
};
|
||||
|
||||
let projectScopes = tierScopes(model.project, project, PROJECT_SCOPE_PREFIX, PROJECT_ALL_SCOPE);
|
||||
let organizationScopes = tierScopes(
|
||||
model.organization,
|
||||
organization,
|
||||
ORGANIZATION_SCOPE_PREFIX,
|
||||
ORGANIZATION_ALL_SCOPE
|
||||
);
|
||||
|
||||
const blocked = projectScopes.length === 0 && organizationScopes.length === 0;
|
||||
|
||||
const identity = model.identity.map((scope) => scope.id);
|
||||
const join = () => [...identity, ...projectScopes, ...organizationScopes].join(' ');
|
||||
|
||||
// Client-side mirror of the server's scope length cap. Unreachable in
|
||||
// practice (the full catalog is ~2.6 KB), but if a selection ever exceeds
|
||||
// it, collapse the larger tier to its requested umbrella and surface that.
|
||||
// Umbrella collapse grants write, so it is off the table under read-only —
|
||||
// the toggle already halves the token list, keeping it well under the cap.
|
||||
let lengthCollapsed = false;
|
||||
if (!readOnly && join().length > MAX_SCOPE_PARAM_LENGTH) {
|
||||
const projectLength = projectScopes.join(' ').length;
|
||||
const organizationLength = organizationScopes.join(' ').length;
|
||||
if (projectLength >= organizationLength && model.project.all) {
|
||||
projectScopes = [PROJECT_ALL_SCOPE];
|
||||
lengthCollapsed = true;
|
||||
} else if (model.organization.all) {
|
||||
organizationScopes = [ORGANIZATION_ALL_SCOPE];
|
||||
lengthCollapsed = true;
|
||||
}
|
||||
if (join().length > MAX_SCOPE_PARAM_LENGTH && model.project.all) {
|
||||
projectScopes = [PROJECT_ALL_SCOPE];
|
||||
lengthCollapsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return { scope: join(), untouched: false, blocked, lengthCollapsed };
|
||||
}
|
||||
|
||||
/** Never granted by a narrowed MCP consent — documented here for tests. */
|
||||
export const NARROWED_GRANT_NEVER_INCLUDES = [ALL_SCOPE];
|
||||
@@ -192,6 +192,14 @@ const PROJECT_RESOURCE_COPY: Record<string, ResourceCopy> = {
|
||||
name: 'Project policies',
|
||||
desc: "This project's security and access policies."
|
||||
},
|
||||
policies: {
|
||||
name: 'Policies',
|
||||
desc: "Legacy access to this project's security and backup policies."
|
||||
},
|
||||
'project.oauth2': {
|
||||
name: 'OAuth2 configuration',
|
||||
desc: "This project's OAuth2 authorization server configuration."
|
||||
},
|
||||
templates: {
|
||||
name: 'Templates',
|
||||
desc: "The project's customizable email and SMS message templates."
|
||||
@@ -236,6 +244,18 @@ const PROJECT_RESOURCE_COPY: Record<string, ResourceCopy> = {
|
||||
name: 'Rows',
|
||||
desc: 'The individual rows of data stored inside your database tables.'
|
||||
},
|
||||
collections: {
|
||||
name: 'Collections',
|
||||
desc: 'Legacy database collections and their structure, replaced by tables.'
|
||||
},
|
||||
attributes: {
|
||||
name: 'Attributes',
|
||||
desc: 'Legacy collection attributes that define document structure, replaced by columns.'
|
||||
},
|
||||
documents: {
|
||||
name: 'Documents',
|
||||
desc: 'Legacy documents stored inside your collections, replaced by rows.'
|
||||
},
|
||||
buckets: {
|
||||
name: 'Storage buckets',
|
||||
desc: 'Storage buckets and their file-level permission and security settings.'
|
||||
@@ -256,6 +276,10 @@ const PROJECT_RESOURCE_COPY: Record<string, ResourceCopy> = {
|
||||
name: 'Executions',
|
||||
desc: 'The execution history and logs of your serverless functions.'
|
||||
},
|
||||
execution: {
|
||||
name: 'Executions (legacy)',
|
||||
desc: 'Legacy access to function executions, replaced by Executions.'
|
||||
},
|
||||
sites: {
|
||||
name: 'Sites',
|
||||
desc: 'Hosted sites and their deployments, builds, and configuration.'
|
||||
@@ -371,6 +395,14 @@ const ORGANIZATION_RESOURCE_COPY: Record<string, ResourceCopy> = {
|
||||
name: 'Organization keys',
|
||||
desc: 'Organization-level API keys that authorize access across projects.'
|
||||
},
|
||||
keys: {
|
||||
name: 'Organization keys (legacy)',
|
||||
desc: 'Legacy access to organization API keys, replaced by Organization keys.'
|
||||
},
|
||||
devKeys: {
|
||||
name: 'Development keys',
|
||||
desc: 'Development keys used to bypass rate limits while building locally.'
|
||||
},
|
||||
domains: {
|
||||
name: 'Organization domains',
|
||||
desc: 'Custom domains owned and managed at the organization level.'
|
||||
@@ -446,16 +478,21 @@ function actionRank(action: string): number {
|
||||
return 2;
|
||||
}
|
||||
|
||||
function actionOf(scope: string): string {
|
||||
/** The action of a bare scope token — `read` in `tables.read`. */
|
||||
export function scopeAction(scope: string): string {
|
||||
const dot = scope.lastIndexOf('.');
|
||||
return dot === -1 ? scope : scope.slice(dot + 1);
|
||||
}
|
||||
|
||||
function resourceOf(scope: string): string {
|
||||
/** The resource of a bare scope token — `tables` in `tables.read`. */
|
||||
export function scopeResource(scope: string): string {
|
||||
const dot = scope.lastIndexOf('.');
|
||||
return dot === -1 ? scope : scope.slice(0, dot);
|
||||
}
|
||||
|
||||
const actionOf = scopeAction;
|
||||
const resourceOf = scopeResource;
|
||||
|
||||
function tierLines(
|
||||
tier: TierScopes,
|
||||
prefix: string,
|
||||
@@ -526,6 +563,63 @@ function tierLines(
|
||||
return lines;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Editor rows — per-resource rows for the MCP consent narrowing editor */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
export interface EditorRow {
|
||||
/** Resource key (everything before the last dot), stable editor identity. */
|
||||
resource: string;
|
||||
/** Display title from the resource catalog, e.g. "Tables". */
|
||||
title: string;
|
||||
/** One-line description of what the resource covers. */
|
||||
description?: string;
|
||||
/** Requested actions for this resource, `read` before `write` before others. */
|
||||
actions: string[];
|
||||
hasRead: boolean;
|
||||
hasWrite: boolean;
|
||||
/** Access chip label for the full requested access, e.g. "Read + Write". */
|
||||
access: string;
|
||||
/** Whether the chip should read as elevated (write access). */
|
||||
accessStrong: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group one tier's requested scopes into per-resource editor rows for the MCP
|
||||
* consent narrowing editor. Same grouping and copy as the read-only summary,
|
||||
* but keyed by resource so each row can be toggled and its access level set.
|
||||
*/
|
||||
export function buildTierEditorRows(tier: TierScopes, prefix: string): EditorRow[] {
|
||||
const copyMap =
|
||||
prefix === PROJECT_SCOPE_PREFIX ? PROJECT_RESOURCE_COPY : ORGANIZATION_RESOURCE_COPY;
|
||||
const groups = new Map<string, string[]>();
|
||||
for (const scope of tier.scopes) {
|
||||
const resource = resourceOf(scope);
|
||||
const bucket = groups.get(resource);
|
||||
if (bucket) bucket.push(scope);
|
||||
else groups.set(resource, [scope]);
|
||||
}
|
||||
return [...groups.entries()].map(([resource, scopes]) => {
|
||||
scopes.sort((a, b) => actionRank(actionOf(a)) - actionRank(actionOf(b)));
|
||||
const actions = scopes.map(actionOf);
|
||||
const { title, description, access, accessStrong } = describeResource(
|
||||
resource,
|
||||
actions,
|
||||
copyMap
|
||||
);
|
||||
return {
|
||||
resource,
|
||||
title,
|
||||
description,
|
||||
actions,
|
||||
hasRead: actions.includes('read'),
|
||||
hasWrite: actions.includes('write'),
|
||||
access,
|
||||
accessStrong
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the read-only permission summary the consent screen displays. Scopes are
|
||||
* not individually selectable — the client decides what it requests — so this is
|
||||
|
||||
@@ -11,13 +11,28 @@
|
||||
IconOfficeBuilding,
|
||||
IconLockClosed,
|
||||
IconExclamationCircle,
|
||||
IconDuplicate
|
||||
IconDuplicate,
|
||||
IconAdjustments,
|
||||
IconShieldCheck
|
||||
} from '@appwrite.io/pink-icons-svelte';
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
|
||||
import { splitConsentScopes, buildConsentPermissions } from '$lib/helpers/oauth2-scopes';
|
||||
import {
|
||||
splitConsentScopes,
|
||||
buildConsentPermissions,
|
||||
buildTierEditorRows,
|
||||
PROJECT_SCOPE_PREFIX,
|
||||
ORGANIZATION_SCOPE_PREFIX,
|
||||
type EditorRow
|
||||
} from '$lib/helpers/oauth2-scopes';
|
||||
import {
|
||||
isMcpGrant,
|
||||
composeGrantedScopes,
|
||||
type TierSelection,
|
||||
type ResourceSelection
|
||||
} from '$lib/helpers/oauth2-mcp';
|
||||
import { isWebRedirect } from '$lib/helpers/oauth2-redirect';
|
||||
import {
|
||||
parseAuthorizationDetails,
|
||||
@@ -116,17 +131,92 @@
|
||||
const permissionGroups = $derived(buildConsentPermissions(scopeModel));
|
||||
let showPermissions = $state(true);
|
||||
|
||||
// MCP grants (detected via the grant's RFC 8707 resources) get a narrowing
|
||||
// editor: the client requested the full scope catalog, so consent is the
|
||||
// control point. Every other grant renders exactly as before — read-only
|
||||
// permissions, no scope narrowing.
|
||||
const canNarrow = $derived(isMcpGrant(grant));
|
||||
|
||||
// The one thing the user controls: which projects / organizations the tiers
|
||||
// are bound to. Defaults to exactly what the client requested; reset on grant
|
||||
// change so a stale selection can't leak.
|
||||
let projectSelected = $state<string[]>([]);
|
||||
let organizationSelected = $state<string[]>([]);
|
||||
|
||||
// Scope-narrowing editor state (MCP grants only). Rows absent from a tier's
|
||||
// selection are selected with full requested access, so the empty record is
|
||||
// the "full access" default.
|
||||
let customize = $state(false);
|
||||
let readOnlyAll = $state(false);
|
||||
let projectSelection = $state<TierSelection>({});
|
||||
let organizationSelection = $state<TierSelection>({});
|
||||
|
||||
$effect(() => {
|
||||
grant.$id;
|
||||
projectSelected = [...projectIdentifiers];
|
||||
organizationSelected = [...organizationIdentifiers];
|
||||
customize = false;
|
||||
readOnlyAll = false;
|
||||
projectSelection = {};
|
||||
organizationSelection = {};
|
||||
});
|
||||
|
||||
const projectRows = $derived(
|
||||
canNarrow ? buildTierEditorRows(scopeModel.project, PROJECT_SCOPE_PREFIX) : []
|
||||
);
|
||||
const organizationRows = $derived(
|
||||
canNarrow ? buildTierEditorRows(scopeModel.organization, ORGANIZATION_SCOPE_PREFIX) : []
|
||||
);
|
||||
|
||||
function sameIdentifiers(a: string[], b: string[]): boolean {
|
||||
return a.length === b.length && a.every((id) => b.includes(id));
|
||||
}
|
||||
const resourcesNarrowed = $derived(
|
||||
!sameIdentifiers(projectSelected, projectIdentifiers) ||
|
||||
!sameIdentifiers(organizationSelected, organizationIdentifiers)
|
||||
);
|
||||
|
||||
// The narrowed grant to send on approve. `scope: undefined` means the user
|
||||
// kept the full request — the approve call then omits `scope` so the server
|
||||
// grants the full literal requested list and re-authorizations skip consent.
|
||||
const composed = $derived(
|
||||
canNarrow
|
||||
? composeGrantedScopes({
|
||||
model: scopeModel,
|
||||
project: projectSelection,
|
||||
organization: organizationSelection,
|
||||
readOnly: readOnlyAll,
|
||||
resourcesNarrowed
|
||||
})
|
||||
: null
|
||||
);
|
||||
|
||||
function rowState(selection: TierSelection, resource: string): ResourceSelection {
|
||||
return selection[resource] ?? { selected: true, level: 'full' };
|
||||
}
|
||||
|
||||
function updateRow(
|
||||
tier: 'project' | 'organization',
|
||||
resource: string,
|
||||
patch: Partial<ResourceSelection>
|
||||
) {
|
||||
const selection = tier === 'project' ? projectSelection : organizationSelection;
|
||||
const next = { ...selection, [resource]: { ...rowState(selection, resource), ...patch } };
|
||||
if (tier === 'project') projectSelection = next;
|
||||
else organizationSelection = next;
|
||||
}
|
||||
|
||||
function setAllRows(tier: 'project' | 'organization', rows: EditorRow[], selected: boolean) {
|
||||
const next: TierSelection = {};
|
||||
for (const row of rows) next[row.resource] = { selected, level: 'full' };
|
||||
if (tier === 'project') projectSelection = next;
|
||||
else organizationSelection = next;
|
||||
}
|
||||
|
||||
function tierAllSelected(rows: EditorRow[], selection: TierSelection): boolean {
|
||||
return rows.every((row) => rowState(selection, row.resource).selected);
|
||||
}
|
||||
|
||||
const projectGranted = $derived(projectRequested && projectSelected.length > 0);
|
||||
const organizationGranted = $derived(organizationRequested && organizationSelected.length > 0);
|
||||
|
||||
@@ -146,7 +236,13 @@
|
||||
!projectGranted &&
|
||||
!organizationGranted
|
||||
);
|
||||
const blocked = $derived(nothingToGrant || projectNeedsResource || organizationNeedsResource);
|
||||
// With the narrowing editor, the selection must keep at least one
|
||||
// non-identity scope — an identity-only grant would leave the app
|
||||
// "authorized" but unable to act.
|
||||
const nothingSelected = $derived(composed?.blocked ?? false);
|
||||
const blocked = $derived(
|
||||
nothingToGrant || projectNeedsResource || organizationNeedsResource || nothingSelected
|
||||
);
|
||||
|
||||
// Resource search wiring. Projects search server-side (there can be many);
|
||||
// organizations are few, so they load once and filter client-side.
|
||||
@@ -191,14 +287,28 @@
|
||||
try {
|
||||
const result = await sdk.forConsole.oauth2.approve({
|
||||
grantId,
|
||||
// Scopes are not downscoped — omit `scope` so the server keeps what
|
||||
// the client requested. Only the resource binding is narrowed.
|
||||
// For MCP grants the editor may downscope the requested catalog;
|
||||
// `scope` stays omitted when the user kept the full request so
|
||||
// the server grants the full literal requested list (keeping the
|
||||
// consent-skip diff empty on re-authorization). Non-MCP grants
|
||||
// never send `scope` — only the resource binding is narrowed.
|
||||
scope: composed?.scope,
|
||||
// Same consent-skip reasoning for the resource binding: on an
|
||||
// MCP grant with untouched pickers, omit `authorizationDetails`
|
||||
// so the server keeps exactly what the client requested — the
|
||||
// re-auth diff (a hash of requested vs stored details) then
|
||||
// stays empty. A narrowed selection is sent and deliberately
|
||||
// forces re-consent on the next full request.
|
||||
authorizationDetails:
|
||||
projectRequested || organizationRequested
|
||||
? serializeGrantedDetails({
|
||||
project: projectGranted ? projectSelected : undefined,
|
||||
organization: organizationGranted ? organizationSelected : undefined
|
||||
})
|
||||
? canNarrow && !resourcesNarrowed
|
||||
? undefined
|
||||
: serializeGrantedDetails({
|
||||
project: projectGranted ? projectSelected : undefined,
|
||||
organization: organizationGranted
|
||||
? organizationSelected
|
||||
: undefined
|
||||
})
|
||||
: undefined
|
||||
});
|
||||
if (grant.$id !== grantId) return;
|
||||
@@ -251,6 +361,88 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
{#snippet editorGroup(
|
||||
tierKey: 'project' | 'organization',
|
||||
heading: string,
|
||||
note: string,
|
||||
rows: EditorRow[],
|
||||
selection: TierSelection
|
||||
)}
|
||||
{#if rows.length > 0}
|
||||
<div class="perm-group">
|
||||
<div class="perm-group-head">
|
||||
<label class="editor-check group-check">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={tierAllSelected(rows, selection)}
|
||||
onchange={(e) => setAllRows(tierKey, rows, e.currentTarget.checked)}
|
||||
disabled={busy} />
|
||||
<Typography.Text variant="m-500" color="--fgcolor-neutral-secondary">
|
||||
{heading}
|
||||
</Typography.Text>
|
||||
</label>
|
||||
<span class="subtext">{note}</span>
|
||||
</div>
|
||||
<ul class="perm-list">
|
||||
{#each rows as row (row.resource)}
|
||||
{@const state = rowState(selection, row.resource)}
|
||||
<li class="perm editor-row" class:off={!state.selected}>
|
||||
<label class="editor-check">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={state.selected}
|
||||
onchange={(e) =>
|
||||
updateRow(tierKey, row.resource, {
|
||||
selected: e.currentTarget.checked
|
||||
})}
|
||||
disabled={busy}
|
||||
aria-label="Allow access to {row.title}" />
|
||||
</label>
|
||||
<span class="perm-text">
|
||||
<span class="perm-row-head">
|
||||
<span class="perm-title">{row.title}</span>
|
||||
{#if row.hasRead && row.hasWrite}
|
||||
<span class="level-toggle" class:disabled={!state.selected}>
|
||||
<button
|
||||
type="button"
|
||||
class="level-btn"
|
||||
class:active={state.level === 'read' || readOnlyAll}
|
||||
disabled={busy || !state.selected}
|
||||
onclick={() =>
|
||||
updateRow(tierKey, row.resource, {
|
||||
level: 'read'
|
||||
})}>
|
||||
Read
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="level-btn"
|
||||
class:active={state.level === 'full' && !readOnlyAll}
|
||||
disabled={busy || !state.selected || readOnlyAll}
|
||||
onclick={() =>
|
||||
updateRow(tierKey, row.resource, {
|
||||
level: 'full'
|
||||
})}>
|
||||
Read + Write
|
||||
</button>
|
||||
</span>
|
||||
{:else}
|
||||
<span class="access-chip" class:strong={row.accessStrong}>
|
||||
{row.access}
|
||||
</span>
|
||||
{/if}
|
||||
</span>
|
||||
{#if row.description}
|
||||
<span class="perm-desc">{row.description}</span>
|
||||
{/if}
|
||||
</span>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
{#snippet copyBtn(token: string)}
|
||||
<button
|
||||
type="button"
|
||||
@@ -302,7 +494,104 @@
|
||||
</header>
|
||||
|
||||
<div class="body">
|
||||
{#if permissionGroups.length > 0}
|
||||
{#if canNarrow}
|
||||
<section class="panel editor-panel">
|
||||
<div class="access-summary">
|
||||
<span class="scope-icon">
|
||||
<Icon icon={IconShieldCheck} size="s" />
|
||||
</span>
|
||||
<span class="scope-head-text">
|
||||
<Typography.Text variant="m-500">
|
||||
{composed?.untouched ? 'Full access' : 'Custom access'}
|
||||
</Typography.Text>
|
||||
<span class="subtext">
|
||||
{composed?.untouched
|
||||
? `${app.name} will be able to manage your organizations, projects, and their data on your behalf.`
|
||||
: `${app.name} only gets the permissions you selected below.`}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="customize-head"
|
||||
aria-expanded={customize}
|
||||
onclick={() => (customize = !customize)}>
|
||||
<span class="customize-label">
|
||||
<span class="customize-icon">
|
||||
<Icon icon={IconAdjustments} size="s" />
|
||||
</span>
|
||||
<span class="scope-head-text">
|
||||
<span class="perm-title">Customize access</span>
|
||||
<span class="subtext"
|
||||
>You can limit {app.name} to specific projects and actions.</span>
|
||||
</span>
|
||||
</span>
|
||||
<Icon icon={customize ? IconChevronUp : IconChevronDown} size="s" />
|
||||
</button>
|
||||
|
||||
{#if customize}
|
||||
<div class="editor-body">
|
||||
<label class="editor-readonly">
|
||||
<input type="checkbox" bind:checked={readOnlyAll} disabled={busy} />
|
||||
<span class="perm-text">
|
||||
<span class="perm-title">Read-only</span>
|
||||
<span class="subtext"
|
||||
>Limit every selected permission to viewing data — nothing
|
||||
can be created, changed, or deleted.</span>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
{#if scopeModel.identity.length > 0}
|
||||
<span class="subtext editor-identity">
|
||||
Basic identity ({scopeModel.identity
|
||||
.map((scope) => scope.id)
|
||||
.join(', ')}) is always shared so {app.name} can recognize your
|
||||
account.
|
||||
</span>
|
||||
{/if}
|
||||
|
||||
{@render editorGroup(
|
||||
'project',
|
||||
'Projects',
|
||||
'Applies only to the projects you select below.',
|
||||
projectRows,
|
||||
projectSelection
|
||||
)}
|
||||
{@render editorGroup(
|
||||
'organization',
|
||||
'Organizations',
|
||||
'Applies only to the organizations you select below.',
|
||||
organizationRows,
|
||||
organizationSelection
|
||||
)}
|
||||
|
||||
{#if nothingSelected}
|
||||
<div class="scope-warning">
|
||||
<Icon
|
||||
icon={IconExclamationCircle}
|
||||
size="s"
|
||||
color="--fgcolor-warning" />
|
||||
<span
|
||||
>Select at least one permission, or {app.name} gets no access
|
||||
at all.</span>
|
||||
</div>
|
||||
{/if}
|
||||
{#if composed?.lengthCollapsed}
|
||||
<div class="scope-warning">
|
||||
<Icon
|
||||
icon={IconExclamationCircle}
|
||||
size="s"
|
||||
color="--fgcolor-warning" />
|
||||
<span
|
||||
>Your selection was too long to grant scope-by-scope, so a
|
||||
fully selected tier was granted as full tier access instead.</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
{:else if permissionGroups.length > 0}
|
||||
<section class="panel">
|
||||
<button
|
||||
type="button"
|
||||
@@ -776,6 +1065,140 @@
|
||||
color: var(--fgcolor-success);
|
||||
}
|
||||
|
||||
/* ---- MCP narrowing editor ----------------------------------------------- */
|
||||
.editor-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.access-summary {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.7rem;
|
||||
padding: 1rem 1rem 0.85rem;
|
||||
}
|
||||
|
||||
.customize-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
padding: 0.85rem 1rem;
|
||||
border: none;
|
||||
border-top: 1px solid var(--border-neutral);
|
||||
background: transparent;
|
||||
color: var(--fgcolor-neutral-primary);
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.customize-head:hover {
|
||||
background: var(--overlay-neutral-hover, var(--bgcolor-neutral-secondary));
|
||||
}
|
||||
|
||||
.customize-label {
|
||||
display: inline-flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.7rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.customize-icon {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border-radius: var(--border-radius-s, 0.5rem);
|
||||
background: var(--bgcolor-neutral-secondary);
|
||||
color: var(--fgcolor-neutral-secondary);
|
||||
}
|
||||
|
||||
.editor-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.1rem;
|
||||
padding: 0.9rem 1rem 1.1rem;
|
||||
border-top: 1px solid var(--border-neutral);
|
||||
max-height: 24rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.editor-readonly {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.7rem;
|
||||
padding: 0.7rem 0.8rem;
|
||||
border: 1px solid var(--border-neutral);
|
||||
border-radius: var(--border-radius-s, 0.5rem);
|
||||
background: var(--bgcolor-neutral-secondary);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.editor-identity {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.editor-check {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.editor-check input[type='checkbox'],
|
||||
.editor-readonly input[type='checkbox'] {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
margin: 0.15rem 0 0;
|
||||
accent-color: var(--bgcolor-neutral-invert);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.editor-row.off .perm-text {
|
||||
opacity: 0.45;
|
||||
}
|
||||
|
||||
.level-toggle {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
border: 1px solid var(--border-neutral-strong);
|
||||
border-radius: 2rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.level-toggle.disabled {
|
||||
opacity: 0.45;
|
||||
}
|
||||
|
||||
.level-btn {
|
||||
padding: 0.1rem 0.55rem;
|
||||
border: none;
|
||||
background: transparent;
|
||||
font-size: 0.58rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.03em;
|
||||
text-transform: uppercase;
|
||||
white-space: nowrap;
|
||||
color: var(--fgcolor-neutral-secondary);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.level-btn + .level-btn {
|
||||
border-left: 1px solid var(--border-neutral-strong);
|
||||
}
|
||||
|
||||
.level-btn.active {
|
||||
background: var(--bgcolor-neutral-invert);
|
||||
color: var(--fgcolor-neutral-on-invert, var(--bgcolor-neutral-primary));
|
||||
}
|
||||
|
||||
.level-btn:disabled {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/* ---- Scope (resource) panels ------------------------------------------ */
|
||||
.scope-panel {
|
||||
display: flex;
|
||||
|
||||
Reference in new issue
Block a user