Skip to content

: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.

feat(oauth): return supports_step_up from token introspection (#127699)

Rafael Audibert12fe79d2a42a
diff --git a/posthog/api/oauth/test_views.py b/posthog/api/oauth/test_views.py
index a5a24f62a4b2..0a581340baca 100644
--- a/posthog/api/oauth/test_views.py
+++ b/posthog/api/oauth/test_views.py
@@ -4355,11 +4355,14 @@ class TestOAuthAPI(APIBaseTest):
data = response.json()
self.assertFalse(data["active"])
- @parameterized.expand([True, False])
- def test_self_introspection_succeeds_without_introspection_scope(self, impersonated: bool) -> None:
+ @parameterized.expand([(True, False), (False, True)])
+ def test_self_introspection_succeeds_without_introspection_scope(
+ self, impersonated: bool, supports_step_up: bool
+ ) -> None:
access_token, _ = self._create_access_and_refresh_tokens(scopes="openid user:read")
access_token.impersonated_by = self.user if impersonated else None
- access_token.save(update_fields=["impersonated_by"])
+ access_token.supports_step_up = supports_step_up
+ access_token.save(update_fields=["impersonated_by", "supports_step_up"])
response = self.post(
"/oauth/introspect/",
@@ -4372,6 +4375,7 @@ class TestOAuthAPI(APIBaseTest):
self.assertTrue(data["active"])
self.assertEqual(data["scope"], "openid user:read")
self.assertEqual(data["is_impersonated"], impersonated)
+ self.assertEqual(data["supports_step_up"], supports_step_up)
def test_self_introspection_via_get_succeeds_without_introspection_scope(self):
"""Self-introspection also works via GET method."""
diff --git a/posthog/api/oauth/views.py b/posthog/api/oauth/views.py
index a2be00da093f..14fae2b3b64d 100644
--- a/posthog/api/oauth/views.py
+++ b/posthog/api/oauth/views.py
@@ -2409,6 +2409,7 @@ def _active_access_token_response(
scoped_organizations: list[str],
application: OAuthApplication | None,
sandbox_task_id: uuid.UUID | None = None,
+ supports_step_up: bool = False,
) -> JsonResponse:
"""RFC 7662 response for an active access token, whether it is stored or a signed JWT."""
data: dict[str, Any] = {
@@ -2416,6 +2417,9 @@ def _active_access_token_response(
"token_type": "access_token",
"scope": scope,
"is_impersonated": is_impersonated,
+ # The MCP server reads this to choose between a 403 insufficient_scope challenge and a
+ # tool error when a scope is missing.
+ "supports_step_up": supports_step_up,
"scoped_teams": scoped_teams,
"scoped_organizations": scoped_organizations,
"exp": expires_at,
@@ -2645,6 +2649,7 @@ class OAuthIntrospectTokenView(ClientProtectedScopedResourceView):
scoped_organizations=access_token.scoped_organizations or [],
application=access_token.application,
sandbox_task_id=access_token.sandbox_task_id,
+ supports_step_up=access_token.supports_step_up,
)
# Fall back to refresh token (lookup by plaintext token — OAuthRefreshToken has