From d878d2140ee958750c7d305bd96f10f6bf3c77d9 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 10 Jun 2021 14:02:19 +0200 Subject: [PATCH] providers/saml: add metadata download link to api Signed-off-by: Jens Langhammer --- authentik/providers/saml/api.py | 18 +++++++++++++++++- schema.yml | 4 ++++ .../providers/saml/SAMLProviderViewPage.ts | 5 ++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/authentik/providers/saml/api.py b/authentik/providers/saml/api.py index 0806b8959..a5cdcf6c7 100644 --- a/authentik/providers/saml/api.py +++ b/authentik/providers/saml/api.py @@ -4,11 +4,17 @@ from xml.etree.ElementTree import ParseError # nosec from defusedxml.ElementTree import fromstring from django.http.response import HttpResponse from django.shortcuts import get_object_or_404 +from django.urls import reverse from django.utils.translation import gettext_lazy as _ from drf_spectacular.types import OpenApiTypes from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema from rest_framework.decorators import action -from rest_framework.fields import CharField, FileField, ReadOnlyField +from rest_framework.fields import ( + CharField, + FileField, + ReadOnlyField, + SerializerMethodField, +) from rest_framework.parsers import MultiPartParser from rest_framework.permissions import AllowAny from rest_framework.relations import SlugRelatedField @@ -37,6 +43,15 @@ LOGGER = get_logger() class SAMLProviderSerializer(ProviderSerializer): """SAMLProvider Serializer""" + metadata_download_url = SerializerMethodField() + + def get_metadata_download_url(self, instance: SAMLProvider) -> str: + """Get metadata download URL""" + return ( + reverse("authentik_api:samlprovider-metadata", kwargs={"pk": instance.pk}) + + "?download" + ) + class Meta: model = SAMLProvider @@ -54,6 +69,7 @@ class SAMLProviderSerializer(ProviderSerializer): "signing_kp", "verification_kp", "sp_binding", + "metadata_download_url", ] diff --git a/schema.yml b/schema.yml index 8ab430338..391797269 100644 --- a/schema.yml +++ b/schema.yml @@ -26576,12 +26576,16 @@ components: title: Service Provider Binding description: This determines how authentik sends the response back to the Service Provider. + metadata_download_url: + type: string + readOnly: true required: - acs_url - assigned_application_name - assigned_application_slug - authorization_flow - component + - metadata_download_url - name - pk - verbose_name diff --git a/web/src/pages/providers/saml/SAMLProviderViewPage.ts b/web/src/pages/providers/saml/SAMLProviderViewPage.ts index 6b191cfd4..cfb648537 100644 --- a/web/src/pages/providers/saml/SAMLProviderViewPage.ts +++ b/web/src/pages/providers/saml/SAMLProviderViewPage.ts @@ -157,14 +157,13 @@ export class SAMLProviderViewPage extends LitElement {