Finish app OAuth callbacks on the workspace host that holds the sign-in cookie
What
App connections (Teams, Slack, Linear, ...) fail on twenty.com since #30153.
#30153 binds each app sign-in to the browser that started it: /auth/apps/authorize sets a host-only __Host- flow cookie, and /auth/apps/callback requires it. On twenty.com the authorize page is served on the workspace host (<workspace>.twenty.com, the front's server base URL), but providers call back on SERVER_URL (api.twenty.com). The browser never sends the workspace host's cookie to api.twenty.com, so every callback fails the browser check. Google and Outlook use their own flow and are not affected. Local dev and CI serve both on one host, which is why nothing caught it.
Fix: a callback that lands on the SERVER_URL host is redirected, with its query string intact, to the same callback path on the workspace host read from the signed state. The sign-in then completes where the cookie lives.
- Redirect URLs registered with providers do not change.
- The browser binding stays.
- Single-host setups (workspace URL host equals
SERVER_URLhost) never redirect, and the redirected request cannot redirect again since it no longer arrives on theSERVER_URLhost. - A state that fails verification is not redirected and falls through to the existing error handling.
Test
New integration case in app-connection-oauth-discovery-flow: a callback sent with the SERVER_URL host is redirected to the workspace host's /auth/apps/callback with the same state and code, and no token request is made on the API host. Typecheck and lint are clean.