providers/saml: fix error when getting metadata of provider with no application

This commit is contained in:
Jens Langhammer 2021-02-16 19:58:04 +01:00
parent 0901d7461e
commit 0b75a0028b
1 changed files with 6 additions and 2 deletions

View File

@ -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)
try:
metadata = DescriptorDownloadView.get_metadata(request, provider)
return Response({"metadata": metadata})
except Provider.application.RelatedObjectDoesNotExist:
return Response({"metadata": ""})
class SAMLPropertyMappingSerializer(ModelSerializer, MetaNameSerializer):