Skip to content

Commit 959544c

Browse files
author
Guillaume Rousse
committed
URL handling simplification
declare only relative URLs in configuration, so as to fix registration when base URL contains a path (issue #179), and expose those endpoints to outer world by appending base URL when needed. This is much simpler than parsing absolute URLs, and more consistent with OIDC frontends behaviour.
1 parent 62f1363 commit 959544c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

example/plugins/backends/saml2_backend.yaml.example

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ config:
6363
allow_unsolicited: true
6464
endpoints:
6565
assertion_consumer_service:
66-
- [<base_url>/<name>/acs/post, 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST']
66+
- [<name>/acs/post, 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST']
6767
discovery_response:
68-
- [<base_url>/<name>/disco, 'urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol']
68+
- [<name>/disco, 'urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol']
6969

7070
# name_id_format: a list of strings to set the <NameIDFormat> element in SP metadata
7171
# name_id_policy_format: a string to set the Format attribute in the NameIDPolicy element

src/satosa/backends/saml2.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def disco_query(self, context):
209209
:return: Response
210210
"""
211211
endpoints = self.sp.config.getattr("endpoints", "sp")
212-
return_url = endpoints["discovery_response"][0][0]
212+
return_url = "{}/{}".format(self.base_url, endpoints["discovery_response"][0][0])
213213

214214
disco_url = (
215215
context.get_decoration(SAMLBackend.KEY_SAML_DISCOVERY_SERVICE_URL)
@@ -303,10 +303,11 @@ def authn_request(self, context, entity_id):
303303

304304
try:
305305
acs_endp, response_binding = self._get_acs(context)
306+
acs_endp_url = "{}/{}".format(self.base_url, acs_endp)
306307
relay_state = util.rndstr()
307308
req_id, binding, http_info = self.sp.prepare_for_negotiated_authenticate(
308309
entityid=entity_id,
309-
assertion_consumer_service_url=acs_endp,
310+
assertion_consumer_service_url=acs_endp_url,
310311
response_binding=response_binding,
311312
relay_state=relay_state,
312313
**kwargs,
@@ -588,8 +589,7 @@ def register_endpoints(self):
588589
url_map = []
589590
sp_endpoints = self.sp.config.getattr("endpoints", "sp")
590591
for endp, binding in sp_endpoints["assertion_consumer_service"]:
591-
parsed_endp = urlparse(endp)
592-
url_map.append(("^%s$" % parsed_endp.path[1:], functools.partial(self.authn_response, binding=binding)))
592+
url_map.append(("^%s$" % endp, functools.partial(self.authn_response, binding=binding)))
593593
if binding == BINDING_HTTP_REDIRECT:
594594
msg = " ".join(
595595
[
@@ -607,9 +607,8 @@ def register_endpoints(self):
607607

608608
if self.discosrv:
609609
for endp, binding in sp_endpoints["discovery_response"]:
610-
parsed_endp = urlparse(endp)
611610
url_map.append(
612-
("^%s$" % parsed_endp.path[1:], self.disco_response))
611+
("^%s$" % endp, self.disco_response))
613612

614613
if self.expose_entityid_endpoint():
615614
logger.debug("Exposing backend entity endpoint = {}".format(self.sp.config.entityid))
@@ -621,6 +620,7 @@ def register_endpoints(self):
621620
url_map.append(
622621
("^%s/%s$" % (self.name, "reload-metadata"), self._reload_metadata))
623622

623+
logger.debug(f"Loaded SAML2 endpoints: {url_map}")
624624
return url_map
625625

626626
def _reload_metadata(self, context):

0 commit comments

Comments
 (0)