Skip to content

Commit 7ed0774

Browse files
committed
Use higher-level function to create a saml request on the saml2 backend
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
1 parent 24b4583 commit 7ed0774

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/satosa/backends/saml2.py

+12-20
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from urllib.parse import urlparse
1111

1212
from saml2 import BINDING_HTTP_REDIRECT
13-
from saml2.client_base import Base
13+
from saml2.client import Saml2Client
1414
from saml2.config import SPConfig
1515
from saml2.extension.mdui import NAMESPACE as UI_NAMESPACE
1616
from saml2.metadata import create_metadata_string
@@ -109,7 +109,7 @@ def __init__(self, outgoing, internal_attributes, config, base_url, name):
109109
self.config = self.init_config(config)
110110

111111
sp_config = SPConfig().load(copy.deepcopy(config[SAMLBackend.KEY_SP_CONFIG]))
112-
self.sp = Base(sp_config)
112+
self.sp = Saml2Client(sp_config)
113113

114114
self.discosrv = config.get(SAMLBackend.KEY_DISCO_SRV)
115115
self.encryption_keys = []
@@ -272,38 +272,30 @@ def authn_request(self, context, entity_id):
272272
kwargs["scoping"] = Scoping(requester_id=[RequesterID(text=requester)])
273273

274274
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-
282275
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-
)
286276
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:
292284
msg = "Failed to construct the AuthnRequest for state"
293285
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
294286
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
296288

297289
if self.sp.config.getattr('allow_unsolicited', 'sp') is False:
298290
if req_id in self.outstanding_queries:
299291
msg = "Request with duplicate id {}".format(req_id)
300292
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
301293
logger.debug(logline)
302294
raise SATOSAAuthenticationError(context.state, msg)
303-
self.outstanding_queries[req_id] = req
295+
self.outstanding_queries[req_id] = req_id
304296

305297
context.state[self.name] = {"relay_state": relay_state}
306-
return make_saml_response(binding, ht_args)
298+
return make_saml_response(binding, http_info)
307299

308300
def authn_response(self, context, binding):
309301
"""

0 commit comments

Comments
 (0)