From 186e5567a386c74908802add07503429084a6ec5 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 23 Jan 2025 11:42:09 +0100 Subject: [PATCH] sources: allow uuid or slug to be used for retrieving a source Signed-off-by: Jens Langhammer --- authentik/sources/kerberos/api/source.py | 1 + authentik/sources/ldap/api.py | 1 + authentik/sources/oauth/api/source.py | 1 + authentik/sources/plex/api/source.py | 1 + authentik/sources/saml/api/source.py | 1 + authentik/sources/scim/api/sources.py | 2 +- schema.yml | 30 +++++++++++++++++++ .../admin/providers/oauth2/OAuth2Sources.ts | 6 ++-- 8 files changed, 40 insertions(+), 3 deletions(-) diff --git a/authentik/sources/kerberos/api/source.py b/authentik/sources/kerberos/api/source.py index cffc0a89400c..9b8120e2e08a 100644 --- a/authentik/sources/kerberos/api/source.py +++ b/authentik/sources/kerberos/api/source.py @@ -66,6 +66,7 @@ class KerberosSourceViewSet(UsedByMixin, ModelViewSet): serializer_class = KerberosSourceSerializer lookup_field = "slug" filterset_fields = [ + "pbm_uuid", "name", "slug", "enabled", diff --git a/authentik/sources/ldap/api.py b/authentik/sources/ldap/api.py index 89ef164cd739..16741caa3ed3 100644 --- a/authentik/sources/ldap/api.py +++ b/authentik/sources/ldap/api.py @@ -110,6 +110,7 @@ class LDAPSourceViewSet(UsedByMixin, ModelViewSet): serializer_class = LDAPSourceSerializer lookup_field = "slug" filterset_fields = [ + "pbm_uuid", "name", "slug", "enabled", diff --git a/authentik/sources/oauth/api/source.py b/authentik/sources/oauth/api/source.py index ebba67d2f260..811049571adf 100644 --- a/authentik/sources/oauth/api/source.py +++ b/authentik/sources/oauth/api/source.py @@ -152,6 +152,7 @@ def filter_has_jwks(self, queryset, name, value): # pragma: no cover class Meta: model = OAuthSource fields = [ + "pbm_uuid", "name", "slug", "enabled", diff --git a/authentik/sources/plex/api/source.py b/authentik/sources/plex/api/source.py index f662fe9f4b5f..c4239e2b301e 100644 --- a/authentik/sources/plex/api/source.py +++ b/authentik/sources/plex/api/source.py @@ -52,6 +52,7 @@ class PlexSourceViewSet(UsedByMixin, ModelViewSet): serializer_class = PlexSourceSerializer lookup_field = "slug" filterset_fields = [ + "pbm_uuid", "name", "slug", "enabled", diff --git a/authentik/sources/saml/api/source.py b/authentik/sources/saml/api/source.py index 5cf4dc7ea60d..0191fccc2a3a 100644 --- a/authentik/sources/saml/api/source.py +++ b/authentik/sources/saml/api/source.py @@ -44,6 +44,7 @@ class SAMLSourceViewSet(UsedByMixin, ModelViewSet): serializer_class = SAMLSourceSerializer lookup_field = "slug" filterset_fields = [ + "pbm_uuid", "name", "slug", "enabled", diff --git a/authentik/sources/scim/api/sources.py b/authentik/sources/scim/api/sources.py index 729e89c7a2f6..d51395a0656e 100644 --- a/authentik/sources/scim/api/sources.py +++ b/authentik/sources/scim/api/sources.py @@ -53,6 +53,6 @@ class SCIMSourceViewSet(UsedByMixin, ModelViewSet): queryset = SCIMSource.objects.all() serializer_class = SCIMSourceSerializer lookup_field = "slug" - filterset_fields = ["name", "slug"] + filterset_fields = ["pbm_uuid", "name", "slug"] search_fields = ["name", "slug", "token__identifier", "token__user__username"] ordering = ["name"] diff --git a/schema.yml b/schema.yml index 85d2875976cf..fbf74d3c91a9 100644 --- a/schema.yml +++ b/schema.yml @@ -26248,6 +26248,11 @@ paths: name: password_login_update_internal_password schema: type: boolean + - in: query + name: pbm_uuid + schema: + type: string + format: uuid - in: query name: realm schema: @@ -26620,6 +26625,11 @@ paths: name: password_login_update_internal_password schema: type: boolean + - in: query + name: pbm_uuid + schema: + type: string + format: uuid - in: query name: peer_certificate schema: @@ -27049,6 +27059,11 @@ paths: description: Number of results to return per page. schema: type: integer + - in: query + name: pbm_uuid + schema: + type: string + format: uuid - in: query name: policy_engine_mode schema: @@ -27418,6 +27433,11 @@ paths: description: Number of results to return per page. schema: type: integer + - in: query + name: pbm_uuid + schema: + type: string + format: uuid - in: query name: policy_engine_mode schema: @@ -27821,6 +27841,11 @@ paths: description: Number of results to return per page. schema: type: integer + - in: query + name: pbm_uuid + schema: + type: string + format: uuid - in: query name: policy_engine_mode schema: @@ -28184,6 +28209,11 @@ paths: description: Number of results to return per page. schema: type: integer + - in: query + name: pbm_uuid + schema: + type: string + format: uuid - name: search required: false in: query diff --git a/web/src/admin/providers/oauth2/OAuth2Sources.ts b/web/src/admin/providers/oauth2/OAuth2Sources.ts index f8dcb910b507..73e571839ffe 100644 --- a/web/src/admin/providers/oauth2/OAuth2Sources.ts +++ b/web/src/admin/providers/oauth2/OAuth2Sources.ts @@ -4,7 +4,7 @@ import { DualSelectPair } from "@goauthentik/elements/ak-dual-select/types"; import { OAuthSource, SourcesApi } from "@goauthentik/api"; const sourceToSelect = (source: OAuthSource) => [ - source.slug, + source.pk, `${source.name} (${source.slug})`, source.name, source, @@ -37,13 +37,15 @@ export function oauth2SourcesSelector(instanceMappings?: string[]) { const oauthSources = new SourcesApi(DEFAULT_CONFIG); const mappings = await Promise.allSettled( instanceMappings.map((instanceId) => - oauthSources.sourcesOauthRetrieve({ slug: instanceId }), + oauthSources.sourcesOauthList({ pbmUuid: instanceId }), ), ); return mappings .filter((s) => s.status === "fulfilled") .map((s) => s.value) + .filter((s) => s.pagination.count > 0) + .map((s) => s.results[0]) .map(sourceToSelect); }; }