Skip to content

fix(platform): add or reconnect exactly the OAuth credential chosen - #3729

Merged
yannickmonney merged 9 commits into
mainfrom
fix/oauth-add-vs-reconnect-intent
Sep 28, 2026
Merged

yannickmonney merged 9 commits into
mainfrom
fix/oauth-add-vs-reconnect-intent

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3711.

Connect and Reconnect previously used the same OAuth start URL, so adding a second account or reconnecting a non-default row could overwrite the default credential. The browser now sends an explicit Add or the selected credential ID. The single-use server state carries that intent through consent; callback query parameters cannot retarget it.

The callback checks the initiating session, current membership and developer capability, then rechecks the selected grant. Grant storage uses one transaction with a connector-pair advisory lock and a lock on the selected credential. Add creates a distinct name and preserves existing credentials; Reconnect preserves the selected ID, name, default choice and references. A disabled credential stays disabled. Slack retains one credential per workspace and refuses reconnecting a row to a different workspace.

Review found and fixed a further authorization race: a member removed or demoted while the token exchange waited could still renew a credential. Storage now locks the member row and repeats the existing authorization check inside its transaction. A revocation committed first refuses the write; one that starts later waits for commit. The pre-exchange check remains.

Migration 0131_connector_oauth_reconnect_target.sql adds nullable reconnect_credential_id. It deliberately has no foreign key, so deleting a target cannot turn a pending Reconnect into Add or erase its refusal context. Legacy pending rows read as Add. The previous image can continue using its original column list during a rolling deployment; callbacks completed by that older image still have its previous behavior.

The three new refusal pages (credential_missing, account_mismatch, forbidden) and their return link support EN/DE/FR using the shared language parser, including DE-CH fallback. Existing refusal kinds retain their existing English behavior. Updated product docs cover all three locales, and the manual/automation registers cover intent, authorization and recovery.

Validation from the independent review:

  • 197 scoped connector/credential server tests, 51 connector settings component tests, and 134 docs structure/i18n tests passed.
  • Real PostgreSQL: 46/46 checks across five OAuth/credential lanes after the authorization correction. The deferred-exchange regression failed for both demotion and removal before the fix; both now refuse without changing credentials. A separate barrier proves the final check waits behind an uncommitted revocation and reads the committed role. Concurrent boot migrations and legacy pending rows are covered.
  • After localization: all 30 renderer/route tests passed (12 new expectations failed before the correction), 178 server tests across OAuth/cloud-import areas passed, and the real PostgreSQL intent lane passed 30/30 on a fresh database.
  • Actual Chromium: 18 keyboard Add/non-default Reconnect/disabled Reconnect handoffs across EN/DE/FR and phone/desktop, 18 translated error-page renders, and 12 translated product-doc renders passed with no page errors or overflow. UI transport was synthetic; real vendor endpoints were not contacted.
  • Platform typecheck, scoped type-aware lint, changed-file format, manual layout/reference checks and connector guide checks passed. Scoped SAST reported no findings.
  • React Doctor reported 84/100: existing snake-case renderer filename and integration-harness status/sequencing diagnostics; no React component defect identified.

Final integration with main 2be6c267e: 215 scoped server tests, 51 component tests, 46/46 real PostgreSQL checks, full platform typecheck, the 1228-box manual gate, and all 18 rebuilt Chromium handoffs passed. The start-door 403 messages were confirmed to be pre-existing on main. Member/SCIM removal lock order is compatible; a pre-existing contention with whole-organization deletion can still roll an OAuth store back as storage_failed.

Whole repository CI must complete on the final pushed head before merge. Local checks above are scoped runs, not a claim that the entire repository gate ran locally.

Integrated the shipped recurrence migration unchanged as 0130_task_repeat.sql; OAuth now follows it as 0131_connector_oauth_reconnect_target.sql. Fresh PostgreSQL boot and the connector-credential, OAuth-intent and recurrence lanes passed 47/47 after this refresh.

yannickmonney and others added 6 commits September 28, 2026 14:58
Every completed consent for a connector without a workspace id (Gmail,
Outlook, Google Drive, Teams) renewed the connector's default grant: a
second account added through Add credential silently replaced the first,
and Reconnect on any other row rewrote the default instead (#3711).

The pending authorization now carries the intent. Migration 0130 adds
app.connector_oauth_states.reconnect_credential_id (NULL = Add, no
foreign key); the start door takes an optional credentialId and keeps it
only when it names an OAuth grant of that organization and connector.
The callback reads the intent from the consumed row alone, re-checks the
initiator's membership and developer role, and refuses a Reconnect whose
credential is gone before redeeming the code.

storeOauth2Grant runs as one transaction under a per-(organization,
connector) advisory lock, row-locks the Reconnect target before reading
the siblings, and lets a pure planner decide: Add stores a new credential
under a free name, Reconnect renews exactly its credential (needs-reauth
cleared, disabled kept) or saves nothing, Slack keeps one credential per
workspace and refuses a Reconnect into another. Every credential create
takes the same pair lock, so concurrent first adds no longer die on the
name or default index. New fixed pages: credential_missing,
account_mismatch, forbidden.

The native-Postgres lane checkConnectorOauthIntent proves each case;
the claim-race probe's initiator is now a member of its organization.
Connect and Reconnect sent the browser to the same start URL, so nothing
told the callback which credential a consent was for (#3711).
goToAuthorization now takes an explicit intent: Add credential > Connect
starts an Add that names no credential, and a row's Reconnect names that
row's id. The parameter name is shared with the start door
(lib/shared/connector-consent.ts), so the page and the door cannot drift
into a Reconnect that silently lands as an Add.
The connector guides promised that Add credential connects another
account and that Reconnect keeps the credential's name and references,
while the product renewed the default grant for both (#3711). EN, DE and
FR now say what each does: every Connect adds a new credential (named
after the connector and numbered, renamed through Edit credential),
Slack keeps one credential per workspace, Reconnect renews exactly the
row it was chosen on and leaves a disabled credential disabled, and a
removed credential, a lost role or another Slack workspace saves nothing.

The connectors manual suite asserts the rows by their masked previews,
explains how to run the consent boxes against a loopback fake vendor,
and gains CONN-F19/F20 and CONN-B7-B10; the automation, pins and
error-code registers name the new coverage and pages.

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed 8596a69b6493774a671e6db0b43b2804995ccaa8 locally. The Add/named-Reconnect behavior, state binding, refusal and expiry controls, deleted-target behavior, concurrent Adds, and Slack workspace behavior pass the scoped native checks.

[P2] Localize the new OAuth recovery pages before shipping. The new credential_missing, account_mismatch, and forbidden messages at services/platform/backend/core/http_connectors/error_page.ts:90–106 are English-only. The shared renderer always emits lang="en" and has no locale input. A local request to the new invalid-Reconnect path with either Accept-Language: de or fr returns 404 with “This credential cannot be reconnected” and “Back to connector settings”. These are new user-facing recovery states, so they must ship in EN/DE/FR under .agents/repo.md's locale rule. The older errors already used this English-only renderer; this finding is the added messages extending that gap, not a claim that the renderer became unlocalized in this PR. Please route them through one localized error surface with translated heading, explanation and back link, and test the native route in EN/DE/FR. Preserve the fixed-copy/escaping and no-store protections.

Independent validation: 83 focused backend tests at this head; 24 affected client tests and 171 docs structural tests on the unchanged UI/docs tree from 15007de31; real-Postgres filtered integration run 30/30, including 13 OAuth intent checks, with only the token response faked. No real provider or production Tale was contacted. This is scoped review, not a full local bun run check or rendered-docs/browser-layout approval.

Parent verification: I also read the changed renderer and replayed the local native EN/DE/FR invalid-target proof at this head; the English-only result and zero external calls reproduced. No additional finding count is assigned to this review comment.

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Re-reviewed 4fbc89ab88a0a979e400ef38861a18544c0ca9ac. The requested locale correction is resolved: all three new recovery pages now provide EN/DE/FR headings, explanations and back links, with matching language metadata. Independent native route checks passed for all three errors and regional/fallback/escaping controls.

Validation at this head: 101 focused backend tests, 24 affected client tests and 20 independent native/renderer cases passed. The OAuth storage, intent, migration and connector UI sources are byte-identical to the previously reviewed implementation; its earlier native integration evidence is retained with that version explicitly recorded. Tests add locale coverage without weakening existing assertions. All testing used local synthetic fixtures and fake provider responses.

No blocking finding remains in this reviewed delta. This is scoped review; no full local bun run check or new browser-layout approval is claimed.

Parent independently read the locale delta and proof and replayed the 20 native/renderer cases successfully.

@yannickmonney
yannickmonney merged commit fa74574 into main Sep 28, 2026
57 checks passed
@yannickmonney
yannickmonney deleted the fix/oauth-add-vs-reconnect-intent branch September 28, 2026 22:08
@yannickmonney

Copy link
Copy Markdown
Contributor Author

TALE-80 review response: evidence at the exact merged head (re: review 5342854423)

Scope. Everything below ran on PR head 2219da9506647956144a25ef9d28df277c2dcd50, collected 2026-09-29 after the merge.

  • The squash fa74574d7 on main carries the same OAuth, recovery-page, migration (0131_connector_oauth_reconnect_target.sql) and connector-docs files. The only difference in those paths is two unrelated catalog keys from newer main.
  • Excluded from this count, because they ran on other revisions: the parent review (8596a69b6), my first-round runs (76c2c3d76), and my unpushed round-2 commits (cf8757067). None of that is a pass of this head.

Localization, in a real browser.

  • Setup:
    • Chromium 1208 drove the real SPA, backend and PostgreSQL.
    • The OAuth vendor was a loopback fake, and all other egress went to a dead proxy, so no real provider was called.
  • Result: 25/25 assertions across the browser locales en-US, de-DE, fr-FR, de-CH and ja-JP. The three new pages render their heading, back link, <html lang> and Content-Language in EN/DE/FR:
    • credential_missing, from the start door and from the callback after a UI Reconnect whose credential was deleted at the consent screen;
    • account_mismatch, from a Slack Reconnect consented in the other workspace;
    • forbidden, for a developer demoted mid-consent.
  • de-CH reads DE and ja reads EN. no-store and the CSP are kept, and the refused start door serves no script and calls no vendor.

Slack.

  • Browser, in every locale above: a Reconnect into the other workspace is refused and writes nothing; a Reconnect in the row's own workspace renews only that row.
  • Native PostgreSQL (backend:integration: checkConnectorCredentials, checkConnectorOauth, checkConnectorOauthIntent, checkSlackInbound, checkConnectorOauthApps, checkCloudImport): 48/48. That covers the 13 intent checks, Slack workspace routing, the claim race and inbound events.
  • Round-1 behaviour probe (EN) re-run at this head: 15/15.

Unit and CI.

  • Unit at this head: server 401/401 (22 files), client 58/58 (7 files).
  • CI on this head: 58 success. The two failures are the post-close "Delete controller/convex PR tags" cleanup jobs for retired images, which main's 02faa8fc1 removes. They are unrelated to this change.

Remaining limitations at this head.

  1. Older kinds stay English. Only the three new pages are localized. invalid_state, vendor_declined, vendor_unreachable, not_configured, unsupported_connector, workspace_claimed and storage_failed stay English with lang="en". A DE/FR reader can therefore meet a German page and then an English one in one flow; the expired-link page was observed in English for de-DE, fr-FR and de-CH.
  2. Copy and matching sit outside the shared mechanisms. The DE/FR copy is hardcoded in error_page.ts, outside the message catalogs, so no parity or voice check sees it. The locale matching (errorLocale) is a local copy of the rule the web and docs servers apply.
  3. Knowledge cloud-import pages. Those doors share the renderer but pass no Accept-Language, so their pages stay English. Their back link goes to /dashboard/<org>/documents but is labelled "Back to connector settings", which predates this PR.
  4. Stale migration number. tests/manual/reference/automation.md (CONN-F15… row) and pins.md (CONN-F19 row) still cite migration 0130. The file is now 0131, and 0130 is task_repeat.
  5. Carried over from round 1.
    • Reconnect cannot verify the account behind a Gmail/Outlook/Drive/Teams consent: the token response names none.
    • During a rolling deploy, a consent this image starts but the previous image completes takes the previous path.

Unmerged follow-up. A change covering items 1–3 exists as two local, unpushed commits on top of 4fbc89ab8: 57f3f70c1 and cf8757067.

  • It covers:
    • all ten kinds and both doors;
    • catalog-backed copy mirrored like INBOX_I18N and guarded by a deep-equal test;
    • the shared negotiateFromAcceptLanguage;
    • the Documents back link;
    • CONN-B11.
  • It is attached to TALE-80 as a patch and a git bundle, and was not pushed, not merged and not deployed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(platform): a second OAuth account or a Reconnect overwrites the default connector credential

1 participant