Skip to content

Commit 035aa3c

Browse files
authored
Implement IdP Scoping parameter for SPs suggesting an entityID to a proxy (#272)
* Document IdP Scoping parameter for SPs * Implement IdP Scoping parameter for SPs suggesting an entityID to a proxy
1 parent 19d07f2 commit 035aa3c

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

djangosaml2/views.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
UnsolicitedResponse)
4444
from saml2.s_utils import UnsupportedBinding
4545
from saml2.saml import SCM_BEARER
46-
from saml2.samlp import AuthnRequest
46+
from saml2.samlp import AuthnRequest, IDPEntry, IDPList, Scoping
4747
from saml2.sigver import MissingKey
4848
from saml2.validate import ResponseLifetimeExceed, ToEarly
4949
from saml2.xmldsig import ( # support for SHA1 is required by spec
@@ -192,6 +192,13 @@ def get(self, request, *args, **kwargs):
192192
if selected_idp is None:
193193
selected_idp = list(configured_idps.keys())[0]
194194

195+
# perform IdP Scoping if scoping param is present
196+
idp_scoping = Scoping()
197+
idp_scoping_param = request.GET.get('scoping', None)
198+
if idp_scoping_param:
199+
idp_scoping.idp_list = IDPList()
200+
idp_scoping.idp_list.idp_entry.append(IDPEntry(provider_id = idp_scoping_param))
201+
195202
# choose a binding to try first
196203
binding = getattr(settings, 'SAML_DEFAULT_BINDING', saml2.BINDING_HTTP_POST)
197204
logger.debug(f'Trying binding {binding} for IDP {selected_idp}')
@@ -253,7 +260,7 @@ def get(self, request, *args, **kwargs):
253260
try:
254261
session_id, result = client.prepare_for_authenticate(
255262
entityid=selected_idp, relay_state=next_path,
256-
binding=binding, sign=sign_requests,
263+
binding=binding, sign=sign_requests, scoping=idp_scoping,
257264
**sso_kwargs)
258265
except TypeError as e:
259266
logger.error(f'{_msg}: {e}')
@@ -294,7 +301,7 @@ def get(self, request, *args, **kwargs):
294301
try:
295302
session_id, result = client.prepare_for_authenticate(
296303
entityid=selected_idp, relay_state=next_path,
297-
binding=binding)
304+
binding=binding, scoping=idp_scoping)
298305
except TypeError as e:
299306
_msg = f"Can't prepare the authentication for {selected_idp}"
300307
logger.error(f'{_msg}: {e}')

docs/source/contents/setup.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,20 @@ For example::
206206

207207
see AARC Blueprint specs `here <https://zenodo.org/record/4596667/files/AARC-G061-A_specification_for_IdP_hinting.pdf>`_.
208208

209+
210+
IdP scoping
211+
===========
212+
The SP can suggest an IdP to a proxy by using the Scoping and IDPList elements in a SAML AuthnRequest. This is done using the `scoping` parameter to the login URL.
213+
214+
``https://sp.example.org/saml2/login/?scoping=https://idp.example.org``
215+
216+
This parameter can be combined with the IdP parameter if multiple IdPs are present in the metadata, otherwise the first is used.
217+
218+
``https://sp.example.org/saml2/login/?scoping=https://idp.example.org&idp=https://proxy.example.com/metadata``
219+
220+
Currently there is support for a single IDPEntry in the IDPList.
221+
222+
209223
Custom and dynamic configuration loading
210224
========================================
211225

0 commit comments

Comments
 (0)