|
43 | 43 | UnsolicitedResponse) |
44 | 44 | from saml2.s_utils import UnsupportedBinding |
45 | 45 | from saml2.saml import SCM_BEARER |
46 | | -from saml2.samlp import AuthnRequest |
| 46 | +from saml2.samlp import AuthnRequest, IDPEntry, IDPList, Scoping |
47 | 47 | from saml2.sigver import MissingKey |
48 | 48 | from saml2.validate import ResponseLifetimeExceed, ToEarly |
49 | 49 | from saml2.xmldsig import ( # support for SHA1 is required by spec |
@@ -192,6 +192,13 @@ def get(self, request, *args, **kwargs): |
192 | 192 | if selected_idp is None: |
193 | 193 | selected_idp = list(configured_idps.keys())[0] |
194 | 194 |
|
| 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 | + |
195 | 202 | # choose a binding to try first |
196 | 203 | binding = getattr(settings, 'SAML_DEFAULT_BINDING', saml2.BINDING_HTTP_POST) |
197 | 204 | logger.debug(f'Trying binding {binding} for IDP {selected_idp}') |
@@ -253,7 +260,7 @@ def get(self, request, *args, **kwargs): |
253 | 260 | try: |
254 | 261 | session_id, result = client.prepare_for_authenticate( |
255 | 262 | entityid=selected_idp, relay_state=next_path, |
256 | | - binding=binding, sign=sign_requests, |
| 263 | + binding=binding, sign=sign_requests, scoping=idp_scoping, |
257 | 264 | **sso_kwargs) |
258 | 265 | except TypeError as e: |
259 | 266 | logger.error(f'{_msg}: {e}') |
@@ -294,7 +301,7 @@ def get(self, request, *args, **kwargs): |
294 | 301 | try: |
295 | 302 | session_id, result = client.prepare_for_authenticate( |
296 | 303 | entityid=selected_idp, relay_state=next_path, |
297 | | - binding=binding) |
| 304 | + binding=binding, scoping=idp_scoping) |
298 | 305 | except TypeError as e: |
299 | 306 | _msg = f"Can't prepare the authentication for {selected_idp}" |
300 | 307 | logger.error(f'{_msg}: {e}') |
|
0 commit comments