Skip to content

feat(data-warehouse): generic OAuth flow starter for inbox sources#3613

Merged
trunk-io[bot] merged 3 commits into
mainfrom
tom/inbox-generic-oauth
Jul 21, 2026
Merged

feat(data-warehouse): generic OAuth flow starter for inbox sources#3613
trunk-io[bot] merged 3 commits into
mainfrom
tom/inbox-generic-oauth

Conversation

@Gilbert09

Copy link
Copy Markdown
Member

Problem

Adding an OAuth-based warehouse source to the Self-driving inbox appeared to require a bespoke
setup form + a per-provider integration service and router. It doesn't — DynamicSourceSetup
already renders oauth and oauth-account-select fields generically (integration/account
listing via getIntegrationsForProject, server-side resource search). The only thing gating
arbitrary providers was the flow starter: OAuthSourceField.startFlow hardcoded
field.kind === "linear" and threw for anything else.

Changes

Make the connect flow generic over the integration kind:

  • core/integrations/integration.ts — a kind-parameterized IntegrationService.startFlow(kind, region, projectId) that launches PostHog's already-generic …/integrations/authorize/?kind=<kind> endpoint (the Linear service is the template; only kind was ever provider-specific).
  • core/integrations/schemas.tsstartGenericIntegrationFlowInput (adds kind); the per-kind linear/slack/github inputs are untouched.
  • core/integrations/identifiers.ts + integrations.module.ts — bind INTEGRATION_SERVICE.
  • host-router/src/routers/integration.router.ts — a generic integration.startFlow tRPC route, registered in appRouter.
  • ui/.../DynamicSourceSetup.tsxOAuthSourceField drops the linear-only branch and calls the generic starter with field.kind (Linear keeps working: same authorize URL).

After this, any OAuth warehouse source PostHog supports (Intercom, HubSpot, Salesforce, Stripe,
the ad platforms, …) connects through the generic form with no provider-specific UI code
just the source's registry entry, whose connect-form schema already carries the oauth field/kind.

How did you test this?

  • New unit test integration.test.ts (authorize URL per kind, url-encoding, failure path).
  • turbo typecheck for @posthog/core, @posthog/host-router, @posthog/ui — pass.
  • biome check on all changed files — clean.

Follow-ups that build on this: Intercom + HubSpot backend emitters (PostHog/posthog) and their
inbox registry entries (a separate code PR).

Generalize the inbox OAuth connect flow so any PostHog-supported OAuth
integration kind works without provider-specific code.

`DynamicSourceSetup` already renders `oauth` and `oauth-account-select`
fields generically (account listing + server-side resource search); the
only provider-specific gate was the flow starter, which hardcoded
`kind === "linear"`. PostHog's `…/integrations/authorize/?kind=<kind>`
endpoint is already generic, so this adds a kind-parameterized
`IntegrationService` + `integration` tRPC router and points the OAuth
field's connect button at it via `field.kind`.

Result: adding an OAuth warehouse source (Intercom, HubSpot, Salesforce,
Stripe, ad platforms, …) needs no bespoke setup form or per-kind router —
just the source's registry entry, whose connect-form schema already
carries the oauth field and kind.
@trunk-io

trunk-io Bot commented Jul 21, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 89ada0c.

The HostRouter type declares an `integration` route, but the desktop
app's trpcRouter assembly did not serve it, tripping the
servesEveryHostRoute compile-time guard and failing typecheck.

Generated-By: PostHog Code
Task-Id: 9fd73e57-6627-4884-bb0e-953cc4fa6b33
Generated-By: PostHog Code
Task-Id: 9fd73e57-6627-4884-bb0e-953cc4fa6b33
@Gilbert09 Gilbert09 added the Stamphog This will request an autostamp by stamphog on small changes label Jul 21, 2026
@Gilbert09
Gilbert09 requested a review from a team July 21, 2026 14:10

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The gates denied this PR because it touches OAuth/auth flows, which are in the deny-list. Additionally, the new router uses ctx.container.get<IntegrationService>(INTEGRATION_SERVICE) — a service-locator call inside a router that is explicitly forbidden by the project's architecture rules. This PR needs a human review before it can be merged.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jul 21, 2026
@trunk-io
trunk-io Bot merged commit 63ae032 into main Jul 21, 2026
37 checks passed
@trunk-io
trunk-io Bot deleted the tom/inbox-generic-oauth branch July 21, 2026 17:26
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.

2 participants