Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// =============================================================================
// MIT License
// Copyright (c) 2026 Aparavi Software AG Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// =============================================================================

import assert from 'node:assert/strict';
import { readdirSync, readFileSync } from 'node:fs';
import path from 'node:path';
import { test } from 'node:test';

import { SERVICE_TIER_SCOPES } from './LoginWithMicrosoftButton';

// The canvas hands the button formContext.provider = the node's protocol name
// (e.g. 'tool_excel'), so the scope map must be keyed by exactly that. Read the
// Microsoft 365 service definitions from the repo so a new service or tier
// cannot ship without scopes.
const M365_NODE_DIR = path.resolve(__dirname, '../../../../../../../../nodes/src/nodes/tool_microsoft_365');

interface M365Service {
file: string;
provider: string;
tiers: string[];
}

function loadServices(): M365Service[] {
return readdirSync(M365_NODE_DIR)
.filter((f) => /^services\..+\.json$/.test(f))
.map((file) => {
const def = JSON.parse(readFileSync(path.join(M365_NODE_DIR, file), 'utf8'));
const provider = String(def.protocol).replace(/:\/\/$/, '');
const accessField = Object.entries(def.fields ?? {}).find(([key]) => key.endsWith('.access'))?.[1] as { enum?: unknown[] } | undefined;
// Enum entries are either bare values or [value, label] pairs.
const tiers = (accessField?.enum ?? []).map((e) => String(Array.isArray(e) ? e[0] : e));
return { file, provider, tiers };
});
}

test('every Microsoft 365 service definition is found with access tiers', () => {
const services = loadServices();
assert.ok(services.length > 0, `no services.*.json under ${M365_NODE_DIR}`);
for (const { file, tiers } of services) assert.ok(tiers.length > 0, `${file} has no <prefix>.access enum`);
});

test('scope map is keyed by node protocol with scopes for every access tier', () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should fix - the same gap is open on the Google button, for four services out of five.

LoginWithGoogleButton.tsx still keeps its SERVICE_TIER_SCOPES inline inside handleHybridSignIn, and that map has exactly one key: tool_gmail.

nodes/src/nodes/tool_google_workspace/ ships five services. Every one of them has an access enum and renders GoogleButtonWidget under google.authType: user:

services file protocol in the map
services.gmail.json tool_gmail yes
services.calendar.json tool_calendar no
services.docs.json tool_docs no
services.drive.json tool_drive no
services.sheets.json tool_sheets no

So four of them send no scope= and fall back to what the comment calls the broker's legacy default consent - the same branch that turned out to grant identity scopes only on the Microsoft side, which is the bug this PR is fixing. Whether Google's legacy default happens to cover those four is the question, and it is worth answering rather than assuming: that assumption is what shipped here.

The cheap move is to export the Google map the way you exported this one, and run this test over both - reading services.*.json from tool_google_workspace for the Google half. If the gap is real the test says so immediately. If the broker's default does cover them, a comment saying so stops the next person asking.

for (const { file, provider, tiers } of loadServices()) {
const byTier = SERVICE_TIER_SCOPES[provider];
assert.ok(byTier, `SERVICE_TIER_SCOPES has no entry for provider '${provider}' (${file})`);
for (const tier of tiers) {
assert.ok(byTier[tier]?.length, `SERVICE_TIER_SCOPES['${provider}'] has no scopes for tier '${tier}' (${file})`);
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,35 @@ import { useTranslation } from 'react-i18next';
import { useCallback, useMemo } from 'react';
import { useFlowProject } from '../../../context/FlowProjectContext';

// =============================================================================
// Scopes
// =============================================================================

/**
* Graph scopes per access tier, keyed by the node's provider — its protocol
* name without '://' (e.g. 'tool_excel'), as passed in formContext.provider —
* the broker
* grants identity plus exactly the requested scopes (least privilege), or its
* legacy default consent when no scope param is sent. Maps mirror the
* per-service AccessSpecs in core/microsoft_access.py. An unknown provider or
* tier sends no scope param rather than guessing another service's scopes.
* offline_access + identity scopes are appended by the broker, matching the
* Google flow.
*/
export const SERVICE_TIER_SCOPES: Record<string, Record<string, string[]>> = {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - the test pins the keys, the scope values can still drift.

This test proves every provider and every tier has an entry. It does not check which scopes, and these values are a hand-kept copy of the AccessSpecs in nodes/src/nodes/core/microsoft_access.py. They match today - I compared all five, including the User.ReadBasic.All that only the widget requests.

If someone raises a tier on the Python side, say word.write to Files.ReadWrite.All, this map keeps requesting the old scope and the symptom is the one you just fixed: consent succeeds, the tool fails at invoke time with "Missing: ...". Nothing goes red on the way there.

How far to take this is your call, and it is a design question rather than a change to make in this PR. The cheap version is a pointer comment in microsoft_access.py saying a second copy lives in this file. The real version is one source that both sides read.

// Graph's workbook API accepts only delegated Files.ReadWrite, reads
// included; the excel readonly tier is a node-side write gate.
tool_excel: { readonly: ['Files.ReadWrite'], write: ['Files.ReadWrite'] },
tool_word: { readonly: ['Files.Read'], write: ['Files.ReadWrite'] },
tool_onedrive: { readonly: ['Files.Read'], write: ['Files.ReadWrite', 'User.ReadBasic.All'] },
tool_outlook_mail: {
readonly: ['Mail.Read'],
send: ['Mail.Read', 'Mail.Send'],
modify: ['Mail.ReadWrite', 'Mail.Send'],
},
tool_outlook_calendar: { readonly: ['Calendars.Read'], write: ['Calendars.ReadWrite'] },
};

// =============================================================================
// Icon
// =============================================================================
Expand Down Expand Up @@ -106,26 +135,7 @@ IconButtonProps<T, S, F> & { formContext?: Record<string, any> }) {
const returnUrl = (oauthReturnUrl || window.location.href).replace('/auth/vscode/google', '/auth/vscode/microsoft');
url.searchParams.set('baseURL', returnUrl);

// Pass the selected tier's scopes explicitly, keyed by the node's
// provider — the broker grants identity plus exactly the requested
// scopes (least privilege), or its legacy default consent when no
// scope param is sent. Maps mirror the per-service AccessSpecs in
// core/microsoft_access.py. An unknown provider or tier sends no scope
// param rather than guessing another service's scopes.
// offline_access + identity scopes are appended by the broker, matching the Google flow.
const SERVICE_TIER_SCOPES: Record<string, Record<string, string[]>> = {
// Graph's workbook API accepts only delegated Files.ReadWrite, reads
// included; the excel readonly tier is a node-side write gate.
excel: { readonly: ['Files.ReadWrite'], write: ['Files.ReadWrite'] },
word: { readonly: ['Files.Read'], write: ['Files.ReadWrite'] },
onedrive: { readonly: ['Files.Read'], write: ['Files.ReadWrite', 'User.ReadBasic.All'] },
outlook_mail: {
readonly: ['Mail.Read'],
send: ['Mail.Read', 'Mail.Send'],
modify: ['Mail.ReadWrite', 'Mail.Send'],
},
outlook_calendar: { readonly: ['Calendars.Read'], write: ['Calendars.ReadWrite'] },
};
// Pass the selected tier's scopes explicitly (see SERVICE_TIER_SCOPES).
const provider = formContext?.provider as string | undefined;
const accessTier = (formValues.access ?? formValues.parameters?.access) as string | undefined;
const tierScopes = provider && accessTier ? SERVICE_TIER_SCOPES[provider]?.[accessTier] : undefined;
Expand Down
Loading