: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
chore(tasks): register mobile callbacks for local oauth (#118574)
Chris Volzer0b8d21ae1ab0
diff --git a/products/tasks/backend/management/commands/setup_tasks_oauth.py b/products/tasks/backend/management/commands/setup_tasks_oauth.pyindex 138622a862f3..334d223c70ee 100644--- a/products/tasks/backend/management/commands/setup_tasks_oauth.py+++ b/products/tasks/backend/management/commands/setup_tasks_oauth.py@@ -12,7 +12,12 @@ from posthog.temporal.oauth import ()from posthog.utils import get_instance_region-ARRAY_REDIRECT_URIS = "http://localhost:8237/callback http://localhost:8239/callback"+# The desktop app's loopback callbacks, plus the custom schemes the mobile app's local, development and+# preview builds sign in with, since all of them use this client against a local stack.+ARRAY_REDIRECT_URIS = (+ "http://localhost:8237/callback http://localhost:8239/callback "+ "posthog://callback posthog-dev://callback posthog-preview://callback"+)POSTHOG_AI_REDIRECT_URIS = "http://localhost:8000/authorize"# Server-minted only: no interactive grant is ever issued against the Signals app, so it has# no real callback. Django requires a redirect URI for the authorization-code grant type.@@ -85,6 +90,13 @@ class Command(BaseCommand):returnself.stdout.write(self.style.SUCCESS(f"OAuthApplication '{app.name}' already exists"))+ # Appended rather than replaced, so a redirect URI a developer added by hand survives.+ registered = app.redirect_uris.split()+ missing = [uri for uri in str(defaults["redirect_uris"]).split() if uri not in registered]+ if missing:+ app.redirect_uris = " ".join([*registered, *missing])+ app.save(update_fields=["redirect_uris"])+ self.stdout.write(self.style.SUCCESS(f" Added redirect URIs to '{app.name}': {' '.join(missing)}"))# Not repaired here: changing the pk means deleting the row, cascading to its tokens.if str(app.id) != defaults["id"]:self.stdout.write(diff --git a/products/tasks/backend/management/commands/test/test_setup_tasks_oauth.py b/products/tasks/backend/management/commands/test/test_setup_tasks_oauth.pyindex ad72e1c130e9..bdff5636bdaa 100644--- a/products/tasks/backend/management/commands/test/test_setup_tasks_oauth.py+++ b/products/tasks/backend/management/commands/test/test_setup_tasks_oauth.py@@ -31,7 +31,10 @@ class TestSetupTasksOAuth(TestCase):"name": "Array Dev App","client_type": OAuthApplication.CLIENT_PUBLIC,"authorization_grant_type": OAuthApplication.GRANT_AUTHORIZATION_CODE,- "redirect_uris": "http://localhost:8237/callback http://localhost:8239/callback",+ "redirect_uris": (+ "http://localhost:8237/callback http://localhost:8239/callback "+ "posthog://callback posthog-dev://callback posthog-preview://callback"+ ),},),(@@ -108,3 +111,22 @@ class TestSetupTasksOAuth(TestCase):call_command("setup_tasks_oauth", stdout=out)assert f"expected {POSTHOG_AI_APP_ID_DEV}" in out.getvalue()++ def test_adds_missing_redirect_uris_to_an_existing_app(self) -> None:+ OAuthApplication.objects.create(+ id=ARRAY_APP_ID_DEV,+ client_id=ARRAY_APP_CLIENT_ID_DEV,+ name="Array Dev App",+ client_type=OAuthApplication.CLIENT_PUBLIC,+ authorization_grant_type=OAuthApplication.GRANT_AUTHORIZATION_CODE,+ redirect_uris="http://localhost:8237/callback http://localhost:9999/callback",+ algorithm="RS256",+ )++ call_command("setup_tasks_oauth", stdout=StringIO())++ app = OAuthApplication.objects.get(client_id=ARRAY_APP_CLIENT_ID_DEV)+ assert app.redirect_uris == (+ "http://localhost:8237/callback http://localhost:9999/callback "+ "http://localhost:8239/callback posthog://callback posthog-dev://callback posthog-preview://callback"+ )