:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(integrations): Make multiple Linear workspace connections possible again (#104836)
posthog[bot]8eaf9381a0b9
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 74f72d3a96b8..14708937421d 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -11141,9 +11141,9 @@ snapshots:scenes-app-settings-environment--settings-environment-details--light:hash: v1.k794b7964.7f92cb7c385f4f8bb553de6f4f5f8bcf0f95d74939ffb374c611ead70f8b127a.AH0AvE6wHb6JceX-md0ofZH6onJ3DFqSku_U5Yk_4ZIscenes-app-settings-environment--settings-environment-error-tracking--dark:- hash: v1.k794b7964.10957f15b2e62332bf3df113d08800cf85acd3ce4bc3cc5dcd3d67c61f381d98.WzOAa4xp3zYZh2b1TCmQ5AmTcHaBH83OxnnSFJ4JH_8+ hash: v1.k794b7964.a71c69507b20c9188543614943522746cf5d72081730c6ac9fd46f70ab9997b8.prAXQY2V-wowVRmWI05vEmSwaG8BNClCW6vQUBIkgx4scenes-app-settings-environment--settings-environment-error-tracking--light:- hash: v1.k794b7964.9b4435125bee69ec16432bab017c8822dcc554ab4b48551f1d817af8c70b3825.wSTcj7MUvVP3zBvhpajH8ZIbdXBmdlCn05--nsVm3XI+ hash: v1.k794b7964.afe4097b75b249199520ed7617be2f9d7bf24aab43b1156221d25155355763c9.q63QkPoqfwsiMY-_6bB1azdvxyTmntafsJv0eg9usPEscenes-app-settings-environment--settings-environment-error-tracking-configuration--dark:hash: v1.k794b7964.5389531656b98551428d0348f86123184edee37f4c3a32fdb4a1cc0869adc3ff.W_v_OXNRYXMUup9iAKFHeMPkwy3iwVpJ6BlmnA6QO_cscenes-app-settings-environment--settings-environment-error-tracking-configuration--light:@@ -11161,9 +11161,9 @@ snapshots:scenes-app-settings-environment--settings-environment-heatmaps-screenshot-cookie--light:hash: v1.k794b7964.32b1f5f6d9cfb399cb097cb13ebe6b9106ee763f92aaf93a9e8fc364c2521f7d.cjrINU6otQ0ckqJ8tOJeoRd2PciUG3lQOeWA-bHE7poscenes-app-settings-environment--settings-environment-integrations--dark:- hash: v1.k794b7964.bf31464f10d36bfd3279dabc491f218cb2963722f82bcbb493e5dc33d29c86b5.fbO-nOzwF7Wo3Hp8O9FbuDPU-9GXMErI99YgmcOUxI8+ hash: v1.k794b7964.7518e0a49a3d5a5a09a9849a81e9be887f6c27e36e1082d085fe3a6fda2aee69.NLu4hnrag8Pc74XrXzIb7HThgfsrdldtumL-Bk1QWvwscenes-app-settings-environment--settings-environment-integrations--light:- hash: v1.k794b7964.1c4f64ff0faa252a5716a1953e687f90e3bf4957dfe82760518afe7b62d6584d.GYBEpi_bgygPDAZD1obHN7o7froCwei8g_abdLcsKw8+ hash: v1.k794b7964.48fdeb2b05b76e7cc7bc2abcea0f66a0cf4f900596c024c7e76d071f2813f758.xYwweP1jNLVERraYTTS_DQfUcwYh-uwjG_vVobYOZ6Mscenes-app-settings-environment--settings-environment-marketing-analytics--dark:hash: v1.k794b7964.fbe1c8ea6c618724c5a7dff5aae9319274afbdfc65e4b306cde2f56ce12d1c3a.GSp7WITJn9Lmmg_WGO7chbCSzHfWvfSwmSU_i1ucrDEscenes-app-settings-environment--settings-environment-marketing-analytics--light:@@ -11181,9 +11181,9 @@ snapshots:scenes-app-settings-environment--settings-environment-product-analytics--light:hash: v1.k794b7964.0f591a3aec17fa23dbe9faaeb8c158d20c851e1f1aef7733ac4dd034e0f77269.YAIPB4LQdDIS6ovHSYMQDhnRWIMG--vbs5iEP6YCGRkscenes-app-settings-environment--settings-environment-replay--dark:- hash: v1.k794b7964.f43e0962e8ceb1edfbed942f0ec3b8046baba1cab40b724076a5663d01ad941a.1iVhypwHCqi04guyeJKa_2TbK5Dvi6rKy2Uf4mzfAOg+ hash: v1.k794b7964.8852a287d49330c9f59ccdce0267a7edfd0bc86f0b1a46b141e27343fc4270b4.ilMUJeezlSbHiHcy3TqrW_sBFHQlVHpFCaCNMTEnLU0scenes-app-settings-environment--settings-environment-replay--light:- hash: v1.k794b7964.9391e7a9690c1163d01458a13e955b71be8e8f4defc1eda94e6dcb77a1f04d31.fxilcM0wFcbr8Y7tw-MZwwzIhuko7dqwToW3EnHYD0M+ hash: v1.k794b7964.5147e158a54bfec734dabc8cb9e8879f13c49bb82fed43a577bc5323404c50ba.I3oDIjhkyw0b6ydOdLk0_FIMbxu0Y5neuzp1DqZQZ4Yscenes-app-settings-environment--settings-environment-revenue-analytics--dark:hash: v1.k794b7964.3f90b2f5a2f28978b0d9ee9e919a072c21c9ceddb7bdd84cfc8c6fe30ff6d05c.TaCU4nl01bOy9YgYzUXUwSt125qI48ONWVstWQwED2Qscenes-app-settings-environment--settings-environment-revenue-analytics--light:@@ -11281,9 +11281,9 @@ snapshots:scenes-app-settings-project--settings-project-details--light:hash: v1.k794b7964.a2695b636aeb73d3eb543ead7ffd3b86e16b47dd49f37ae15565cb6286796dc5.f6rKh3QIZOs_ryn3iWbfQfCMr_ruAoiC_Ac0Ru_fNJQscenes-app-settings-project--settings-project-integrations--dark:- hash: v1.k794b7964.bf31464f10d36bfd3279dabc491f218cb2963722f82bcbb493e5dc33d29c86b5.yDZsN-V7mNvv7zdaVUNPpq_7M-7fQr7o42LRqg610pQ+ hash: v1.k794b7964.a936f2e7e13dd839822febecb4718a94a5e30a2aa90e200fd54ab0be6f58f73d.cUIvZCHSlHzVhJdaAUNCmkWWtAmQ2ldBmjKnULj3IxYscenes-app-settings-project--settings-project-integrations--light:- hash: v1.k794b7964.1c4f64ff0faa252a5716a1953e687f90e3bf4957dfe82760518afe7b62d6584d.FUV0OFF_hZG8eaMsdWuTimsUmdWRaRFOA9w_Yms3R74+ hash: v1.k794b7964.8d5b1e5b3bd1292fc19ade8bb1de27b610fcdba89ec6e406a8fb5bcc980902cb.z4llkwWnuUuBTVPh5iA1ag1mLvhiPEBQX7R_clSk5_Escenes-app-settings-project--settings-project-logs--dark:hash: v1.k794b7964.49d053d0783c37817aef5a402d8b00781837f6d4fcf96ce8018dcc439ee744f6.XDbj-HU8eX-2niM5nkM6KmkxOLY_sD30DE6_93XKRsUscenes-app-settings-project--settings-project-logs--light:@@ -11309,9 +11309,9 @@ snapshots:scenes-app-settings-project--settings-project-product-analytics--light:hash: v1.k794b7964.8d3750bf59ddadc3ea14cd751b7573883bfcdda5d3b2cbe6845ef3722aed3af8.LUJwxW-jfEvrQCES5BKC1nc7i1Bs9H3dCmvApLsQl7kscenes-app-settings-project--settings-project-replay--dark:- hash: v1.k794b7964.f43e0962e8ceb1edfbed942f0ec3b8046baba1cab40b724076a5663d01ad941a.0sIsd4cQMNUDkAyhcfHSNogMrtWg-lPeGLvvz17lkCs+ hash: v1.k794b7964.8852a287d49330c9f59ccdce0267a7edfd0bc86f0b1a46b141e27343fc4270b4.8qMVyM-x3QfyvJAOgwMaJiTxnH2dg5dojErOxb2uN6Mscenes-app-settings-project--settings-project-replay--light:- hash: v1.k794b7964.9391e7a9690c1163d01458a13e955b71be8e8f4defc1eda94e6dcb77a1f04d31.bntfgUVcHzzl_cONcGMAVCSshIoxWP1JvXnD1L9lNCo+ hash: v1.k794b7964.5147e158a54bfec734dabc8cb9e8879f13c49bb82fed43a577bc5323404c50ba.a7eg1ambAcJKiIaenXezTxO21W3PJtqTVQeP-wChrS4scenes-app-settings-project--settings-project-surveys--dark:hash: v1.k794b7964.b2de0cd0533566c2406e9c66bcbe6a83c6f7b2bd0e1862027ba36a33a78624d1.D6LgyASNsXWSr98qx80h-brseJENrtIOMEJsSNN9sUoscenes-app-settings-project--settings-project-surveys--light:diff --git a/frontend/src/scenes/integrations/components/Integrations.tsx b/frontend/src/scenes/integrations/components/Integrations.tsxindex 5aff66986475..f4f546dbfc0d 100644--- a/frontend/src/scenes/integrations/components/Integrations.tsx+++ b/frontend/src/scenes/integrations/components/Integrations.tsx@@ -1,9 +1,10 @@import { useValues } from 'kea'-import { useState } from 'react'+import { ReactNode, useState } from 'react'import { LemonButton } from '@posthog/lemon-ui'import api from 'lib/api'+import { cn } from 'lib/utils/css-classes'import { GitLabSetupModal } from 'scenes/integrations/gitlab/GitLabSetupModal'import { teamLogic } from 'scenes/teamLogic'import { urls } from 'scenes/urls'@@ -27,7 +28,22 @@ export function GitLabIntegration({ centered }: { centered?: boolean } = {}): JS}export function LinearIntegration({ next, centered }: { next?: string; centered?: boolean }): JSX.Element {- return <OAuthIntegration kind="linear" connectText="Connect workspace" next={next} centered={centered} />+ // Switching workspace on Linear's approval screen drops the OAuth request, so the workspace+ // has to be selected in Linear before the flow starts.+ return (+ <OAuthIntegration+ kind="linear"+ connectText="Connect workspace"+ next={next}+ centered={centered}+ hint={+ <>+ Before connecting, open Linear in a new tab and switch to the workspace you want to connect to. Then+ come back here and click <strong>Connect workspace</strong>.+ </>+ }+ />+ )}export function JiraIntegration({ next, centered }: { next?: string; centered?: boolean }): JSX.Element {@@ -39,11 +55,13 @@ const OAuthIntegration = ({connectText,next,centered,+ hint,}: {kind: IntegrationKindconnectText: stringnext?: stringcentered?: boolean+ hint?: ReactNode}): JSX.Element => {const { currentTeam } = useValues(teamLogic)const settingsPath = next ?? urls.settings('environment-integrations')@@ -52,11 +70,22 @@ const OAuthIntegration = ({kind,})+ const connectButton = (+ <LemonButton type="secondary" disableClientSideRouting to={authorizationUrl}>+ {connectText}+ </LemonButton>+ )+return (<Integration kind={kind} centered={centered}>- <LemonButton type="secondary" disableClientSideRouting to={authorizationUrl}>- {connectText}- </LemonButton>+ {hint ? (+ <div className={cn('flex flex-col gap-y-4', centered ? 'items-center text-center' : 'items-start')}>+ {connectButton}+ <p className="m-0 text-xs text-secondary">{hint}</p>+ </div>+ ) : (+ connectButton+ )}</Integration>)}diff --git a/posthog/models/integration/oauth.py b/posthog/models/integration/oauth.pyindex 213291e6e056..801eddc96eef 100644--- a/posthog/models/integration/oauth.py+++ b/posthog/models/integration/oauth.py@@ -610,7 +610,10 @@ class OauthIntegration:return OauthConfig(authorize_url="https://linear.app/oauth/authorize",- additional_authorize_params={"actor": "application"},+ # Linear skips its approval screen once the app is authorized, and that screen holds+ # the only workspace switcher, so without `prompt=consent` a person with more than+ # one workspace can never connect anything but the first one.+ additional_authorize_params={"actor": "application", "prompt": "consent"},token_url="https://api.linear.app/oauth/token",token_info_url="https://api.linear.app/graphql",token_info_graphql_query="{ viewer { organization { id name urlKey } } }",diff --git a/posthog/models/test/integration/test_oauth.py b/posthog/models/test/integration/test_oauth.pyindex 668b735b9408..d81d336dadbf 100644--- a/posthog/models/test/integration/test_oauth.py+++ b/posthog/models/test/integration/test_oauth.py@@ -64,6 +64,8 @@ class TestOauthIntegrationModel(BaseTest):"LINKEDIN_APP_CLIENT_SECRET": "linkedin-client-secret","TIKTOK_ADS_CLIENT_ID": "tiktok-app-id","TIKTOK_ADS_CLIENT_SECRET": "tiktok-secret",+ "LINEAR_APP_CLIENT_ID": "linear-client-id",+ "LINEAR_APP_CLIENT_SECRET": "linear-client-secret",}def create_integration(@@ -147,6 +149,15 @@ class TestOauthIntegrationModel(BaseTest):== "https://accounts.google.com/o/oauth2/v2/auth?client_id=google-client-id&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&redirect_uri=https%3A%2F%2Flocalhost%3A8010%2Fintegrations%2Fgoogle-ads%2Fcallback&response_type=code&state=next%3D%252Fprojects%252Ftest%26token%3Dstate_token&access_type=offline&prompt=consent")+ def test_linear_authorize_url_forces_the_approval_screen(self):+ # Without the prompt, a person with several Linear workspaces never sees the switcher.+ with self.settings(**self.mock_settings):+ url = OauthIntegration.authorize_url("linear", token="state_token", next="/projects/test")+ params = {k: v[0] for k, v in parse_qs(url.partition("?")[2]).items()}++ assert params["prompt"] == "consent"+ assert params["actor"] == "application"+def test_authorize_url_google_calendar(self):with self.settings(**self.mock_settings):url = OauthIntegration.authorize_url("google-calendar", token="state_token", next="/projects/test")