Skip to content

feat(salesforce): delegated OAuth authorization for writeback (#994) - #1313

Merged
athvin merged 1 commit into
mainfrom
feat/994-delegated-auth
Nov 27, 2026
Merged

athvin merged 1 commit into
mainfrom
feat/994-delegated-auth

Conversation

@athvin

@athvin athvin commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #994

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

sf_oauth (PKCE web-server flow, identity binding, refresh, revoke), four writeback-authorization routes, the worker-side access_token, two entities, a chart value, and the provider/deploy contract in connectors.md §4.3.1.

#994: writeback must act as a consenting reviewer, not as extraction's client credentials. #995 (journaled apply) depends on it.

Proof

pg_sf_delegated_auth against a mock Salesforce: code exchange (a wrong PKCE verifier is refused), identity binding, a token for another instance and an identity naming another org both refused (tenant confusion), refresh classified ok / transient (503) / denied / revoked, no response body in errors; routes: 503 unconfigured, viewer 403, non-allowlisted redirect 422, cross-org 404, forged state 409, another admin completing someone else's flow 409, state single-use; access_token refuses unattended use without consent, revokes on invalid_grant, then NotAuthorized (no client-credentials fallback); GET never carries a token. make check exit 0; schema replay/race tests pass.

Risk & rollback

Additive tables and routes; the flow answers 503 until a redirect is configured. git revert <merge-sha>.

Post-merge ledger

Closed by: agent · session Claude Code:24d16c2e-fec6-49d8-9797-060338df4848 on brians-MacBook-Pro · 2026-11-27T06:19:12Z

  • main is green with this change on it — the merge SHA, and the run
    that proves it. A later head SHA with this commit as an ancestor counts;
    a cancelled run with zero jobs does not: — 7d1ca93, rust 45949549054 + frontend 45949549083 success
  • images built, or correctly never ran because nothing that goes into
    an image changed: — success, run 45949548993
  • deploy converged — proved by a line the running process emitted, not
    by the image digest and not by the workflow conclusion: — run 45949975076 success; the live process serves the new routes: https://dupezero.com/api/openapi lists writeback-authorization, which only the new image has
  • the push-only surface no pull request can pre-test (deploy, drift,
    kind's nightly leg) is green, or knowingly red for a reason that is not
    this change: — deploy, infra, devcontainer, marketing preview all success on 7d1ca93
  • the board card reached Done through the automation rather than by
    hand, and the issue closed: — E9: Add delegated Salesforce authorization for writeback #994 CLOSED by feat(salesforce): delegated OAuth authorization for writeback (#994) #1313 via automation
  • follow-ups are open for everything deferred here — numbers: — none; no portal callback page is owed until a tenant configures a redirect
  • what was learned is written down where the next session will find it
    (a skill, a reference, memory) — or nothing new was learned: — nothing new beyond the PR's Discoveries (PII span gate matches the literal url.query)

Specific to this change

  • the deploy reconciles salesforce_oauth_states and salesforce_delegated_grants — the new pod serves (boot reconcile refuses to start on a failed apply), run 45949975076
Context — plan, discoveries, measurements, files

Plan

Discoveries

  • No portal callback page exists; the API contract is that whatever page sits at an allowlisted redirect posts code+state to …/complete. The chart value stays empty (503) until one is configured.
  • The PII span gate flags the literal text url.query anywhere in product source, including a Url::query_pairs_mut() call.

Measurements

Files

🤖 Generated with Claude Code

Writeback acts as a reviewing Salesforce user who consented, never as the
extraction's client credentials.

- sf_oauth: the OAuth 2.0 web-server flow with PKCE (S256) and a single-use
  state stored only as its SHA-256; code exchange, identity binding (the
  identity service's org and user must match the id URL, and the token's
  instance must be the connection's), refresh, and revocation. Errors carry
  Salesforce's error code, never a body or token; every call re-checks the
  outbound URL guard and never follows a redirect.
- Routes under /v1/orgs/{org}/connections/{id}/writeback-authorization:
  POST start (Admin, redirect allowlisted by ER_SF_OAUTH_REDIRECT_URIS, 503
  when unset), POST complete (the state must be this org's, this
  connection's, unexpired, unused and started by the same principal), GET
  (Viewer, no tokens), DELETE (Admin, revokes here and best-effort at
  Salesforce).
- access_token() for the writeback worker: refuses unattended use unless
  the grant allows it; Salesforce invalid_grant marks the grant revoked
  (consent_withdrawn) so nothing retries a dead grant; no fallback.
- Entities salesforce_oauth_state and salesforce_delegated_grant; the
  refresh token and verifier are each returned by exactly one statement.
- Chart value erserver.salesforceOAuthRedirectUris; provider requirements
  and deploy configuration in connectors.md §4.3.1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The marketing preview was removed because this PR is closed or merged.

@athvin
athvin merged commit 7d1ca93 into main Nov 27, 2026
48 checks passed
@athvin
athvin temporarily deployed to marketing-preview November 27, 2026 06:04 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
marketing-preview — b19bdeca Deployed Nov 27, 2026 by athvin via remove closed PR previews #97
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.

E9: Add delegated Salesforce authorization for writeback

2 participants