From 0b75a0028bf79ac2f0afdef57a5bbe503c8a6a67 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 16 Feb 2021 19:58:04 +0100 Subject: [PATCH] providers/saml: fix error when getting metadata of provider with no application --- authentik/providers/saml/api.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/authentik/providers/saml/api.py b/authentik/providers/saml/api.py index 1163afe95..150e8a816 100644 --- a/authentik/providers/saml/api.py +++ b/authentik/providers/saml/api.py @@ -10,6 +10,7 @@ from rest_framework.viewsets import ModelViewSet from authentik.core.api.providers import ProviderSerializer from authentik.core.api.utils import MetaNameSerializer +from authentik.core.models import Provider from authentik.providers.saml.models import SAMLPropertyMapping, SAMLProvider from authentik.providers.saml.views.metadata import DescriptorDownloadView @@ -60,8 +61,11 @@ class SAMLProviderViewSet(ModelViewSet): def metadata(self, request: Request, pk: int) -> Response: """Return metadata as XML string""" provider = get_object_or_404(SAMLProvider, pk=pk) - metadata = DescriptorDownloadView.get_metadata(request, provider) - return Response({"metadata": metadata}) + try: + metadata = DescriptorDownloadView.get_metadata(request, provider) + return Response({"metadata": metadata}) + except Provider.application.RelatedObjectDoesNotExist: + return Response({"metadata": ""}) class SAMLPropertyMappingSerializer(ModelSerializer, MetaNameSerializer):