: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(google-search-console): offer the google account chooser on connect (#126708)
Tom Owersec9bf0d9834d
diff --git a/posthog/models/integration/oauth.py b/posthog/models/integration/oauth.pyindex f9bf837c1932..1c377df51252 100644--- a/posthog/models/integration/oauth.py+++ b/posthog/models/integration/oauth.py@@ -771,7 +771,9 @@ class OauthIntegration:elif kind == "google-search-console":return OauthConfig(authorize_url="https://accounts.google.com/o/oauth2/v2/auth",- additional_authorize_params={"access_type": "offline", "prompt": "consent"},+ # `consent` forces a refresh token. `select_account` always shows the account chooser,+ # so a user whose signed-in account owns no property can reconnect with the one that does.+ additional_authorize_params={"access_type": "offline", "prompt": "consent select_account"},token_info_url="https://openidconnect.googleapis.com/v1/userinfo",token_info_config_fields=["sub", "email"],token_url="https://oauth2.googleapis.com/token",diff --git a/posthog/models/test/integration/test_oauth.py b/posthog/models/test/integration/test_oauth.pyindex 51245fd310ce..0cffd02bd36e 100644--- a/posthog/models/test/integration/test_oauth.py+++ b/posthog/models/test/integration/test_oauth.py@@ -68,6 +68,8 @@ class TestOauthIntegrationModel(BaseTest):"GOOGLE_ADS_APP_CLIENT_SECRET": "google-client-secret","GOOGLE_CALENDAR_APP_CLIENT_ID": "google-calendar-client-id","GOOGLE_CALENDAR_APP_CLIENT_SECRET": "google-calendar-client-secret",+ "GOOGLE_SEARCH_CONSOLE_APP_CLIENT_ID": "google-search-console-client-id",+ "GOOGLE_SEARCH_CONSOLE_APP_CLIENT_SECRET": "google-search-console-client-secret","LINKEDIN_APP_CLIENT_ID": "linkedin-client-id","LINKEDIN_APP_CLIENT_SECRET": "linkedin-client-secret","TIKTOK_ADS_CLIENT_ID": "tiktok-app-id",@@ -112,6 +114,13 @@ class TestOauthIntegrationModel(BaseTest):"code_challenge_method": "S256",}+ def test_google_search_console_authorize_url_offers_the_account_chooser(self):+ with self.settings(**self.mock_settings):+ url = OauthIntegration.authorize_url("google-search-console", token="state_token", next="/projects/test")+ params = {k: v[0] for k, v in parse_qs(url.partition("?")[2]).items()}+ assert params["access_type"] == "offline"+ assert set(params["prompt"].split(" ")) == {"consent", "select_account"}+def test_authorize_url_carries_initiating_team_id_in_state(self):with self.settings(**self.mock_settings):url = OauthIntegration.authorize_url(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/source.pyindex 3d498a4f5df1..1dce9c15ee2f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/source.py@@ -68,8 +68,8 @@ _LIST_SITES_ERROR = (# that no longer works. Telling a user to reconnect covers only the last one._PROPERTY_LIST_QUOTA_ERROR = "Google is rate limiting Search Console requests. Wait a minute, then try again."_PROPERTY_LIST_ACCESS_ERROR = (- "The connected Google account can't read any Search Console property. Reconnect and allow "- "Search Console access, or use the account that owns the property."+ "The connected Google account can't read any Search Console property. Reconnect, choose the "+ "account that has access to your property, and allow Search Console access.")_PROPERTY_LIST_CREDENTIALS_ERROR = ("Google rejected the credentials for this connection. Reconnect your Google account, then pick a property."