: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(oauth): advertise the introspection scope in discovery metadata (#95509)
posthog[bot]11e530d4c909
diff --git a/posthog/api/oauth/test_views.py b/posthog/api/oauth/test_views.pyindex df5f57061c8e..8229586ddb2b 100644--- a/posthog/api/oauth/test_views.py+++ b/posthog/api/oauth/test_views.py@@ -5512,6 +5512,9 @@ class TestOAuthClientManifest(APIBaseTest):for scope in get_oauth_scopes_supported():with self.subTest(scope=scope):self.assertIn(f"`{scope}`", body)+ # A scope with no description falls back to its own name, so an+ # advertised scope nobody wrote a line for reads as "`x`: x".+ self.assertNotIn(f"`{scope}`: {scope}", body)def test_manifest_accessible_without_authentication(self):self.client.logout()diff --git a/posthog/api/oauth/views.py b/posthog/api/oauth/views.pyindex f20c964d737d..9af542415977 100644--- a/posthog/api/oauth/views.py+++ b/posthog/api/oauth/views.py@@ -2463,11 +2463,15 @@ class OAuthProtectedResourceMetadataView(_PublicMetadataView):return JsonResponse(metadata)-# OIDC scopes have no entry in get_scope_descriptions(), which only covers obj:action scopes.-_OIDC_SCOPE_DESCRIPTIONS = {+# Identity and token-management scopes have no entry in get_scope_descriptions(),+# which only covers obj:action scopes. Every bare scope in+# `get_oauth_scopes_supported()` needs a line here, or the manifest prints the+# scope name where its description belongs.+_IDENTITY_SCOPE_DESCRIPTIONS = {"openid": "Sign in and read your user identifier","profile": "Read your basic profile","email": "Read your email address",+ "introspection": "Check whether a token you hold is still valid",}@@ -2485,7 +2489,7 @@ class OAuthClientManifestView(_PublicMetadataView):descriptions = get_scope_descriptions()scopes = [- (scope, descriptions[scope] if scope in descriptions else _OIDC_SCOPE_DESCRIPTIONS.get(scope, scope))+ (scope, descriptions[scope] if scope in descriptions else _IDENTITY_SCOPE_DESCRIPTIONS.get(scope, scope))for scope in get_oauth_scopes_supported()]diff --git a/posthog/scopes.py b/posthog/scopes.pyindex a3254b936049..18dff5a34d8b 100644--- a/posthog/scopes.py+++ b/posthog/scopes.py@@ -561,13 +561,18 @@ def get_oauth_scopes_supported() -> list[str]:(the latter generated at build time via `bin/build-mcp-oauth-scopes.py` sothe protected resource cannot drift out of subset of the AS).- Built from `UNPRIVILEGED_SCOPES`, so it excludes all three non-advertised- classes: `INTERNAL_API_SCOPE_OBJECTS` (server-mint-only, e.g.- `signal_scout_internal` — never user-grantable), `OAUTH_SCOPES_HIDDEN`- (alpha / PAT-only), and `PRIVILEGED_SCOPES` (`llm_gateway:*`, admin-granted- only). Discovery metadata shouldn't advertise scopes an OAuth client can't- obtain self-serve. PAT validation uses `get_scope_descriptions()` directly- and is unaffected.+ Resource scopes are built from `UNPRIVILEGED_SCOPES`, so the list excludes+ all three non-advertised classes: `INTERNAL_API_SCOPE_OBJECTS`+ (server-mint-only, e.g. `signal_scout_internal` — never user-grantable),+ `OAUTH_SCOPES_HIDDEN` (alpha / PAT-only), and `PRIVILEGED_SCOPES`+ (`llm_gateway:*`, admin-granted only). Discovery metadata shouldn't advertise+ scopes an OAuth client can't obtain self-serve. PAT validation uses+ `get_scope_descriptions()` directly and is unaffected.++ Every `ALWAYS_ALLOWED_SCOPES` member is advertised too, because those ride on+ every token we issue whether the client asks for them or not. A client that+ requests one and cannot find it here reads that as consent granted only in+ part, and warns the user at the moment of install.The Signals scout harness sandbox token carries `signal_scout_internal:write`,but it is minted by directly inserting an `OAuthAccessToken` row (see@@ -581,4 +586,8 @@ def get_oauth_scopes_supported() -> list[str]:ordered = [f"{obj}:{action}" for obj in API_SCOPE_OBJECTS for action in API_SCOPE_ACTIONS if f"{obj}:{action}" in visible]- return list(OIDC_SCOPES) + ordered+ # `OIDC_SCOPES` keeps its declared order at the head of the list, so only the+ # remaining always-allowed scopes are appended (sorted to keep the generated+ # MCP artifact byte-stable).+ other_always_allowed = sorted(ALWAYS_ALLOWED_SCOPES - set(OIDC_SCOPES))+ return list(OIDC_SCOPES) + other_always_allowed + ordereddiff --git a/posthog/test/test_scopes.py b/posthog/test/test_scopes.pyindex dcfa11c34898..46b005c16e39 100644--- a/posthog/test/test_scopes.py+++ b/posthog/test/test_scopes.py@@ -10,12 +10,12 @@ from parameterized import parameterizedfrom posthog.scopes import (ALL_SCOPES,+ ALWAYS_ALLOWED_SCOPES,API_SCOPE_ACTIONS,API_SCOPE_OBJECTS,INTERNAL_API_SCOPE_OBJECTS,OAUTH_HIDDEN_SCOPE_OBJECTS,OAUTH_SCOPES_HIDDEN,- OIDC_SCOPES,PRIVILEGED_SCOPES,PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION,UNPRIVILEGED_SCOPES,@@ -140,11 +140,9 @@ class TestScopeSets(BaseTest):self.assertNotIn("llm_gateway:read", supported)self.assertNotIn("llm_gateway:write", supported)- def test_oauth_scopes_supported_includes_oidc_and_unprivileged(self) -> None:+ def test_oauth_scopes_supported_includes_always_allowed_and_unprivileged(self) -> None:supported = set(get_oauth_scopes_supported())- for oidc in OIDC_SCOPES:- self.assertIn(oidc, supported)- self.assertEqual(supported - set(OIDC_SCOPES), UNPRIVILEGED_SCOPES)+ self.assertEqual(supported - ALWAYS_ALLOWED_SCOPES, UNPRIVILEGED_SCOPES)def test_project_secret_api_keys_exclude_user_bound_customer_task_scopes(self) -> None:# Customer task endpoints need a user for RBAC and activity attribution.@@ -178,10 +176,17 @@ class TestGetOAuthScopesSupported(SimpleTestCase):"OAuth metadata — internal scopes must never be advertised or user-grantable.")- def test_oidc_scopes_are_advertised(self) -> None:- scopes = get_oauth_scopes_supported()- for oidc in ("openid", "profile", "email"):- assert oidc in scopes+ def test_always_allowed_scopes_are_advertised(self) -> None:+ # Every ALWAYS_ALLOWED_SCOPES member is granted on every token, so discovery+ # metadata that omits one under-reports what the token carries. Clients such as+ # ChatGPT compare the scopes they asked for against `scopes_supported` and warn+ # the user that consent was only partly granted.+ advertised = set(get_oauth_scopes_supported())+ for scope in ALWAYS_ALLOWED_SCOPES:+ assert scope in advertised, (+ f"{scope} is granted on every token via ALWAYS_ALLOWED_SCOPES but is missing from "+ "`scopes_supported` in OAuth discovery metadata."+ )class TestGetScopeDescriptions(SimpleTestCase):diff --git a/services/mcp/src/lib/oauth-scopes.generated.ts b/services/mcp/src/lib/oauth-scopes.generated.tsindex 17743b32310b..12229b37001d 100644--- a/services/mcp/src/lib/oauth-scopes.generated.ts+++ b/services/mcp/src/lib/oauth-scopes.generated.ts@@ -11,6 +11,7 @@ export const OAUTH_SCOPES_SUPPORTED = ['openid','profile','email',+ 'introspection','action:read','action:write','access_control:read',