Skip to content

Commit 3bcbd9c

Browse files
authored
Fix filtering on SAML provider (supabase#29636)
1 parent bc203b9 commit 3bcbd9c

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

apps/studio/components/interfaces/Auth/AuthProvidersFormValidation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ const PROVIDER_SAML = {
13831383
$schema: JSON_SCHEMA_VERSION,
13841384
type: 'object',
13851385
title: 'SAML 2.0',
1386-
link: 'https://supabase.com/docs/guides/auth/enterprise-sso',
1386+
link: 'https://supabase.com/docs/guides/auth/enterprise-sso/auth-sso-saml',
13871387
properties: {
13881388
SAML_ENABLED: {
13891389
title: 'Enable SAML 2.0 Single Sign-on',

apps/studio/data/auth/users-count-query.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ const getUsersCountSQl = ({
4141
}
4242

4343
if (providers && providers.length > 0) {
44-
conditions.push(
45-
`(raw_app_meta_data->>'providers')::jsonb ?| array[${providers.map((p) => `'${p}'`).join(', ')}]`
46-
)
44+
// [Joshen] This is arguarbly not fully optimized, but at the same time not commonly used
45+
// JFYI in case we do eventually run into performance issues here when filtering for SAML provider
46+
if (providers.includes('saml 2.0')) {
47+
conditions.push(
48+
`(select jsonb_agg(case when value ~ '^sso' then 'sso' else value end) from jsonb_array_elements_text((raw_app_meta_data ->> 'providers')::jsonb)) ?| array[${providers.map((p) => (p === 'saml 2.0' ? `'sso'` : `'${p}'`)).join(', ')}]`.trim()
49+
)
50+
} else {
51+
conditions.push(
52+
`(raw_app_meta_data->>'providers')::jsonb ?| array[${providers.map((p) => `'${p}'`).join(', ')}]`
53+
)
54+
}
4755
}
4856

4957
const combinedConditions = conditions.map((x) => `(${x})`).join(' and ')

apps/studio/data/auth/users-infinite-query.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,17 @@ const getUsersSQL = ({
5656
}
5757

5858
if (providers && providers.length > 0) {
59-
conditions.push(
60-
`(raw_app_meta_data->>'providers')::jsonb ?| array[${providers.map((p) => `'${p}'`).join(', ')}]`
61-
)
59+
// [Joshen] This is arguarbly not fully optimized, but at the same time not commonly used
60+
// JFYI in case we do eventually run into performance issues here when filtering for SAML provider
61+
if (providers.includes('saml 2.0')) {
62+
conditions.push(
63+
`(select jsonb_agg(case when value ~ '^sso' then 'sso' else value end) from jsonb_array_elements_text((raw_app_meta_data ->> 'providers')::jsonb)) ?| array[${providers.map((p) => (p === 'saml 2.0' ? `'sso'` : `'${p}'`)).join(', ')}]`.trim()
64+
)
65+
} else {
66+
conditions.push(
67+
`(raw_app_meta_data->>'providers')::jsonb ?| array[${providers.map((p) => `'${p}'`).join(', ')}]`
68+
)
69+
}
6270
}
6371

6472
const combinedConditions = conditions.map((x) => `(${x})`).join(' and ')

0 commit comments

Comments
 (0)