Skip to content

Commit 8aaa984

Browse files
authored
Merge pull request #327 from cheoppy/mdq_fetch_fix
Added a step to fetch the selected idp when using MDQ
2 parents 5f956aa + 0b4324c commit 8aaa984

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Diff for: djangosaml2/utils.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from django.core.exceptions import ImproperlyConfigured
2323
from django.http import HttpResponse, HttpResponseRedirect
2424
from django.shortcuts import resolve_url
25+
from saml2.mdstore import MetaDataMDX
2526

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

4041

41-
def available_idps(config: SPConfig, langpref=None) -> dict:
42+
def available_idps(config: SPConfig, langpref=None, idp_to_check: str = None) -> dict:
4243
if langpref is None:
4344
langpref = "en"
4445

4546
idps = set()
4647

4748
for metadata in config.metadata.metadata.values():
49+
# initiate a fetch to the selected idp when using MDQ, otherwise the MetaDataMDX is an empty database
50+
if isinstance(metadata, MetaDataMDX) and idp_to_check:
51+
m = metadata[idp_to_check]
4852
result = metadata.any("idpsso_descriptor", "single_sign_on_service")
4953
if result:
5054
idps.update(result.keys())

Diff for: djangosaml2/views.py

+4
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ def get(self, request, *args, **kwargs):
245245
},
246246
)
247247

248+
# when using MDQ and DS we need to initiate a check on the selected idp,
249+
# otherwise the available idps will be empty
250+
configured_idps = available_idps(conf, idp_to_check=selected_idp)
251+
248252
# is the first one, otherwise next logger message will print None
249253
if not configured_idps: # pragma: no cover
250254
raise IdPConfigurationMissing("IdP is missing or its metadata is expired.")

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def read(*rnames):
2727

2828
setup(
2929
name="djangosaml2",
30-
version="1.3.6",
30+
version="1.4.0",
3131
description="pysaml2 integration for Django",
3232
long_description=read("README.md"),
3333
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)