: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): show readable labels for hidden scopes in consent screen (#65955)
Fernando Gomesd3b7d1e37c89
diff --git a/frontend/src/lib/scopes.test.ts b/frontend/src/lib/scopes.test.tsindex 5f3c1e87a020..7a775ec1914c 100644--- a/frontend/src/lib/scopes.test.ts+++ b/frontend/src/lib/scopes.test.ts@@ -1,5 +1,5 @@import { AGENT_USE_CASE_SCOPES } from 'lib/agentScopes.generated'-import { AGENT_CLI_API_KEY_SCOPES, API_KEY_SCOPE_PRESETS, API_SCOPES } from 'lib/scopes'+import { AGENT_CLI_API_KEY_SCOPES, API_KEY_SCOPE_PRESETS, API_SCOPES, getScopeDescription } from 'lib/scopes'const getRenderableKeyCreationScopes = (): Set<string> =>new Set(@@ -10,6 +10,24 @@ const getRenderableKeyCreationScopes = (): Set<string> =>))+describe('getScopeDescription', () => {+ it('returns the known description for a recognised scope', () => {+ expect(getScopeDescription('user:read')).toBe('Read access to users')+ })++ it('derives a readable label for OAuth-hidden scopes absent from API_SCOPES', () => {+ expect(getScopeDescription('wizard_session:write')).toBe('Write access to wizard session')+ })++ it('returns undefined for introspection so list call sites can filter it out', () => {+ expect(getScopeDescription('introspection')).toBeUndefined()+ })++ it('returns the bare scope string when there is no colon separator', () => {+ expect(getScopeDescription('baretoken')).toBe('baretoken')+ })+})+describe('API_KEY_SCOPE_PRESETS', () => {const findPreset = (value: string): (typeof API_KEY_SCOPE_PRESETS)[number] => {const preset = API_KEY_SCOPE_PRESETS.find((p) => p.value === value)diff --git a/frontend/src/lib/scopes.tsx b/frontend/src/lib/scopes.tsxindex 2fe0ac26bfe0..3c66feb7a1bc 100644--- a/frontend/src/lib/scopes.tsx+++ b/frontend/src/lib/scopes.tsx@@ -122,6 +122,7 @@ export const API_SCOPES: APIScope[] = [{ key: 'property_definition', objectName: 'Property definition', objectPlural: 'property definitions' },{ key: 'query', objectName: 'Query', objectPlural: 'queries', disabledActions: ['write'] },// `query_performance` is omitted — OAuth-hidden, PAT-grantable only (see `OAUTH_HIDDEN_SCOPE_OBJECTS` in posthog/scopes.py).+ // `wizard_session` is also omitted for the same reason.{ key: 'replay_scanner', objectName: 'Replay scanner', objectPlural: 'replay scanners' },{ key: 'revenue_analytics', objectName: 'Revenue analytics', objectPlural: 'revenue analytics' },{ key: 'session_recording', objectName: 'Session recording', objectPlural: 'session recordings' },@@ -317,6 +318,7 @@ export const getScopeDescription = (scope: string): string | undefined => {}if (scope === 'introspection') {+ // OAuth-internal scope — never shown to users; list call sites .filter(Boolean) it out.return undefined}@@ -326,12 +328,14 @@ export const getScopeDescription = (scope: string): string | undefined => {return scope}+ const actionWord = action === 'write' ? 'Write' : 'Read'+const scopeObject = API_SCOPES.find((s) => s.key === object)if (!scopeObject) {- // Unknown / hidden scope — call sites .filter(Boolean) the result.- return undefined+ // OAuth-hidden scope (e.g. wizard_session, query_performance) — absent from API_SCOPES,+ // so derive a readable label from the raw key rather than surfacing the raw identifier.+ return `${actionWord} access to ${object.replace(/_/g, ' ')}`}- const actionWord = action === 'write' ? 'Write' : 'Read'return `${actionWord} access to ${scopeObject.objectPlural}`}