Skip to content

Commit

Permalink
Merge pull request #327 from cheoppy/mdq_fetch_fix
Browse files Browse the repository at this point in the history
Added a step to fetch the selected idp when using MDQ
  • Loading branch information
peppelinux authored Mar 21, 2022
2 parents 5f956aa + 0b4324c commit 8aaa984
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion djangosaml2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import resolve_url
from saml2.mdstore import MetaDataMDX

try:
from django.utils.http import url_has_allowed_host_and_scheme
Expand All @@ -38,13 +39,16 @@ def get_custom_setting(name: str, default=None):
return getattr(settings, name, default)


def available_idps(config: SPConfig, langpref=None) -> dict:
def available_idps(config: SPConfig, langpref=None, idp_to_check: str = None) -> dict:
if langpref is None:
langpref = "en"

idps = set()

for metadata in config.metadata.metadata.values():
# initiate a fetch to the selected idp when using MDQ, otherwise the MetaDataMDX is an empty database
if isinstance(metadata, MetaDataMDX) and idp_to_check:
m = metadata[idp_to_check]
result = metadata.any("idpsso_descriptor", "single_sign_on_service")
if result:
idps.update(result.keys())
Expand Down
4 changes: 4 additions & 0 deletions djangosaml2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ def get(self, request, *args, **kwargs):
},
)

# when using MDQ and DS we need to initiate a check on the selected idp,
# otherwise the available idps will be empty
configured_idps = available_idps(conf, idp_to_check=selected_idp)

# is the first one, otherwise next logger message will print None
if not configured_idps: # pragma: no cover
raise IdPConfigurationMissing("IdP is missing or its metadata is expired.")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def read(*rnames):

setup(
name="djangosaml2",
version="1.3.6",
version="1.4.0",
description="pysaml2 integration for Django",
long_description=read("README.md"),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 8aaa984

Please sign in to comment.