Skip to content

Commit c26cf7d

Browse files
committed
Implement IdP Scoping parameter for SPs suggesting an entityID to a proxy
1 parent 7ac3694 commit c26cf7d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-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}')

0 commit comments

Comments
 (0)