providers/saml: don't error if no request in API serializer context

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2023-01-03 00:14:16 +01:00
parent ffed653cae
commit 57400925a4
No known key found for this signature in database
1 changed files with 8 additions and 0 deletions

View File

@ -47,6 +47,8 @@ class SAMLProviderSerializer(ProviderSerializer):
def get_url_download_metadata(self, instance: SAMLProvider) -> str:
"""Get metadata download URL"""
if "request" not in self._context:
return ""
request: HttpRequest = self._context["request"]._request
return request.build_absolute_uri(
reverse("authentik_api:samlprovider-metadata", kwargs={"pk": instance.pk}) + "?download"
@ -54,6 +56,8 @@ class SAMLProviderSerializer(ProviderSerializer):
def get_url_sso_post(self, instance: SAMLProvider) -> str:
"""Get SSO Post URL"""
if "request" not in self._context:
return ""
request: HttpRequest = self._context["request"]._request
try:
return request.build_absolute_uri(
@ -67,6 +71,8 @@ class SAMLProviderSerializer(ProviderSerializer):
def get_url_sso_redirect(self, instance: SAMLProvider) -> str:
"""Get SSO Redirect URL"""
if "request" not in self._context:
return ""
request: HttpRequest = self._context["request"]._request
try:
return request.build_absolute_uri(
@ -80,6 +86,8 @@ class SAMLProviderSerializer(ProviderSerializer):
def get_url_sso_init(self, instance: SAMLProvider) -> str:
"""Get SSO IDP-Initiated URL"""
if "request" not in self._context:
return ""
request: HttpRequest = self._context["request"]._request
try:
return request.build_absolute_uri(