From 029d58191eb64a7d5e8818881b09b2b611d3639b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 8 Jun 2021 17:22:03 +0200 Subject: [PATCH] sources/saml: include metadata download link in API response Signed-off-by: Jens Langhammer --- authentik/flows/api/stages.py | 5 ++-- authentik/providers/saml/api.py | 1 + authentik/sources/saml/api.py | 8 ++++- schema.yml | 4 +++ web/src/api/legacy.ts | 3 -- .../pages/sources/saml/SAMLSourceViewPage.ts | 29 ++++++++++--------- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/authentik/flows/api/stages.py b/authentik/flows/api/stages.py index a9c271a82..d14acf700 100644 --- a/authentik/flows/api/stages.py +++ b/authentik/flows/api/stages.py @@ -1,7 +1,7 @@ """Flow Stage API Views""" from typing import Iterable -from django.urls.base import reverse +from django.urls.base import reverse from drf_spectacular.utils import extend_schema from rest_framework import mixins from rest_framework.decorators import action @@ -100,7 +100,8 @@ class StageViewSet( user_settings.initial_data["object_uid"] = str(stage.pk) if hasattr(stage, "configure_flow"): user_settings.initial_data["configure_flow"] = reverse( - "authentik_flows:configure", kwargs={"stage_uuid": stage.uuid.hex}, + "authentik_flows:configure", + kwargs={"stage_uuid": stage.uuid.hex}, ) if not user_settings.is_valid(): LOGGER.warning(user_settings.errors) diff --git a/authentik/providers/saml/api.py b/authentik/providers/saml/api.py index 1e337fede..52fbe2061 100644 --- a/authentik/providers/saml/api.py +++ b/authentik/providers/saml/api.py @@ -60,6 +60,7 @@ class SAMLMetadataSerializer(PassiveSerializer): """SAML Provider Metadata serializer""" metadata = ReadOnlyField() + download_url = ReadOnlyField(required=False) class SAMLProviderImportSerializer(PassiveSerializer): diff --git a/authentik/sources/saml/api.py b/authentik/sources/saml/api.py index 88cde35cb..81cbcf8fb 100644 --- a/authentik/sources/saml/api.py +++ b/authentik/sources/saml/api.py @@ -1,4 +1,5 @@ """SAMLSource API Views""" +from django.urls import reverse from drf_spectacular.utils import extend_schema from rest_framework.decorators import action from rest_framework.request import Request @@ -46,4 +47,9 @@ class SAMLSourceViewSet(ModelViewSet): """Return metadata as XML string""" source = self.get_object() metadata = MetadataProcessor(source, request).build_entity_descriptor() - return Response({"metadata": metadata}) + return Response( + { + "metadata": metadata, + "download_url": reverse("authentik_sources_saml:metadata"), + } + ) diff --git a/schema.yml b/schema.yml index ab60c6026..5d001d51b 100644 --- a/schema.yml +++ b/schema.yml @@ -24313,7 +24313,11 @@ components: metadata: type: string readOnly: true + download_url: + type: string + readOnly: true required: + - download_url - metadata SAMLPropertyMapping: type: object diff --git a/web/src/api/legacy.ts b/web/src/api/legacy.ts index c6f5d209e..bcddb5da1 100644 --- a/web/src/api/legacy.ts +++ b/web/src/api/legacy.ts @@ -1,8 +1,5 @@ export class AppURLManager { - static sourceSAML(slug: string, rest: string): string { - return `/source/saml/${slug}/${rest}`; - } static sourceOAuth(slug: string, action: string): string { return `/source/oauth/${action}/${slug}/`; } diff --git a/web/src/pages/sources/saml/SAMLSourceViewPage.ts b/web/src/pages/sources/saml/SAMLSourceViewPage.ts index 69cd9d592..989700056 100644 --- a/web/src/pages/sources/saml/SAMLSourceViewPage.ts +++ b/web/src/pages/sources/saml/SAMLSourceViewPage.ts @@ -23,7 +23,6 @@ import "../../policies/BoundPoliciesList"; import "./SAMLSourceForm"; import { SAMLSource, SourcesApi } from "authentik-api"; import { DEFAULT_CONFIG } from "../../../api/Config"; -import { AppURLManager } from "../../../api/legacy"; import { EVENT_REFRESH } from "../../../constants"; import { ifDefined } from "lit-html/directives/if-defined"; @@ -135,19 +134,21 @@ export class SAMLSourceViewPage extends LitElement {
-
- ${until(new SourcesApi(DEFAULT_CONFIG).sourcesSamlMetadataRetrieve({ - slug: this.source.slug, - }).then(m => { - return html``; - }) - )} -
- + ${until(new SourcesApi(DEFAULT_CONFIG).sourcesSamlMetadataRetrieve({ + slug: this.source.slug, + }).then(m => { + return html` +
+ +
+ + `; + }) + )}