|
10 | 10 | from urllib.parse import urlparse |
11 | 11 |
|
12 | 12 | from saml2 import BINDING_HTTP_REDIRECT |
13 | | -from saml2.client_base import Base |
| 13 | +from saml2.client import Saml2Client |
14 | 14 | from saml2.config import SPConfig |
15 | 15 | from saml2.extension.mdui import NAMESPACE as UI_NAMESPACE |
16 | 16 | from saml2.metadata import create_metadata_string |
@@ -109,7 +109,7 @@ def __init__(self, outgoing, internal_attributes, config, base_url, name): |
109 | 109 | self.config = self.init_config(config) |
110 | 110 |
|
111 | 111 | sp_config = SPConfig().load(copy.deepcopy(config[SAMLBackend.KEY_SP_CONFIG])) |
112 | | - self.sp = Base(sp_config) |
| 112 | + self.sp = Saml2Client(sp_config) |
113 | 113 |
|
114 | 114 | self.discosrv = config.get(SAMLBackend.KEY_DISCO_SRV) |
115 | 115 | self.encryption_keys = [] |
@@ -272,38 +272,30 @@ def authn_request(self, context, entity_id): |
272 | 272 | kwargs["scoping"] = Scoping(requester_id=[RequesterID(text=requester)]) |
273 | 273 |
|
274 | 274 | try: |
275 | | - binding, destination = self.sp.pick_binding( |
276 | | - "single_sign_on_service", None, "idpsso", entity_id=entity_id |
277 | | - ) |
278 | | - msg = "binding: {}, destination: {}".format(binding, destination) |
279 | | - logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg) |
280 | | - logger.debug(logline) |
281 | | - |
282 | 275 | acs_endp, response_binding = self.sp.config.getattr("endpoints", "sp")["assertion_consumer_service"][0] |
283 | | - req_id, req = self.sp.create_authn_request( |
284 | | - destination, binding=response_binding, **kwargs |
285 | | - ) |
286 | 276 | relay_state = util.rndstr() |
287 | | - ht_args = self.sp.apply_binding(binding, "%s" % req, destination, relay_state=relay_state) |
288 | | - msg = "ht_args: {}".format(ht_args) |
289 | | - logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg) |
290 | | - logger.debug(logline) |
291 | | - except Exception as exc: |
| 277 | + req_id, binding, http_info = self.sp.prepare_for_negotiated_authenticate( |
| 278 | + entityid=entity_id, |
| 279 | + response_binding=response_binding, |
| 280 | + relay_state=relay_state, |
| 281 | + **kwargs, |
| 282 | + ) |
| 283 | + except Exception as e: |
292 | 284 | msg = "Failed to construct the AuthnRequest for state" |
293 | 285 | logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg) |
294 | 286 | logger.debug(logline, exc_info=True) |
295 | | - raise SATOSAAuthenticationError(context.state, "Failed to construct the AuthnRequest") from exc |
| 287 | + raise SATOSAAuthenticationError(context.state, "Failed to construct the AuthnRequest") from e |
296 | 288 |
|
297 | 289 | if self.sp.config.getattr('allow_unsolicited', 'sp') is False: |
298 | 290 | if req_id in self.outstanding_queries: |
299 | 291 | msg = "Request with duplicate id {}".format(req_id) |
300 | 292 | logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg) |
301 | 293 | logger.debug(logline) |
302 | 294 | raise SATOSAAuthenticationError(context.state, msg) |
303 | | - self.outstanding_queries[req_id] = req |
| 295 | + self.outstanding_queries[req_id] = req_id |
304 | 296 |
|
305 | 297 | context.state[self.name] = {"relay_state": relay_state} |
306 | | - return make_saml_response(binding, ht_args) |
| 298 | + return make_saml_response(binding, http_info) |
307 | 299 |
|
308 | 300 | def authn_response(self, context, binding): |
309 | 301 | """ |
|
0 commit comments