Skip to content

Commit 8c9fc6a

Browse files
committed
Refactor create_authn_request assertion_consumer_service_url
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent f42c3f8 commit 8c9fc6a

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

src/saml2/client_base.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -313,30 +313,25 @@ def create_authn_request(self, destination, vorg="", scoping=None,
313313

314314
args = {}
315315

316-
if self.config.getattr('hide_assertion_consumer_service', 'sp'):
316+
# AssertionConsumerServiceURL
317+
# AssertionConsumerServiceIndex
318+
hide_assertion_consumer_service = self.config.getattr('hide_assertion_consumer_service', 'sp')
319+
assertion_consumer_service_url = (
320+
kwargs.pop("assertion_consumer_service_urls", [None])[0]
321+
or kwargs.pop("assertion_consumer_service_url", None)
322+
)
323+
assertion_consumer_service_index = kwargs.pop("assertion_consumer_service_index", None)
324+
service_url = (self.service_urls(service_url_binding or binding) or [None])[0]
325+
if hide_assertion_consumer_service:
317326
args["assertion_consumer_service_url"] = None
318327
binding = None
319-
else:
320-
try:
321-
args["assertion_consumer_service_url"] = kwargs[
322-
"assertion_consumer_service_urls"][0]
323-
del kwargs["assertion_consumer_service_urls"]
324-
except KeyError:
325-
try:
326-
args["assertion_consumer_service_url"] = kwargs[
327-
"assertion_consumer_service_url"]
328-
del kwargs["assertion_consumer_service_url"]
329-
except KeyError:
330-
try:
331-
args["assertion_consumer_service_index"] = str(
332-
kwargs["assertion_consumer_service_index"])
333-
del kwargs["assertion_consumer_service_index"]
334-
except KeyError:
335-
if service_url_binding is None:
336-
service_urls = self.service_urls(binding)
337-
else:
338-
service_urls = self.service_urls(service_url_binding)
339-
args["assertion_consumer_service_url"] = service_urls[0]
328+
elif assertion_consumer_service_url:
329+
args["assertion_consumer_service_url"] = assertion_consumer_service_url
330+
elif assertion_consumer_service_index:
331+
args["assertion_consumer_service_index"] = assertion_consumer_service_index
332+
elif service_url:
333+
args["assertion_consumer_service_url"] = service_url
334+
340335

341336
try:
342337
args["provider_name"] = kwargs["provider_name"]

0 commit comments

Comments
 (0)