@@ -117,7 +117,7 @@ def register_endpoints(self, backend_names):
117117
118118 if self .enable_metadata_reload ():
119119 url_map .append (
120- ("^%s/%s$" % (self .name , "reload-metadata" ), self ._reload_metadata ))
120+ ("^%s/%s$" % (self .endpoint_basepath , "reload-metadata" ), self ._reload_metadata ))
121121
122122 self .idp_config = self ._build_idp_config_endpoints (
123123 self .config [self .KEY_IDP_CONFIG ], backend_names )
@@ -511,15 +511,19 @@ def _register_endpoints(self, providers):
511511 """
512512 url_map = []
513513
514+ backend_providers = "|" .join (providers )
515+ base_path = urlparse (self .base_url ).path .lstrip ("/" )
516+ if base_path :
517+ base_path = base_path + "/"
514518 for endp_category in self .endpoints :
515519 for binding , endp in self .endpoints [endp_category ].items ():
516- valid_providers = ""
517- for provider in providers :
518- valid_providers = "{}|^{}" . format ( valid_providers , provider )
519- valid_providers = valid_providers . lstrip ( "|" )
520- parsed_endp = urlparse ( endp )
521- url_map . append (( "(%s)/%s$" % ( valid_providers , parsed_endp . path ),
522- functools . partial ( self . handle_authn_request , binding_in = binding )) )
520+ endp_path = urlparse ( endp ). path
521+ url_map . append (
522+ (
523+ "^{}({})/{}$" . format ( base_path , backend_providers , endp_path ),
524+ functools . partial ( self . handle_authn_request , binding_in = binding )
525+ )
526+ )
523527
524528 if self .expose_entityid_endpoint ():
525529 logger .debug ("Exposing frontend entity endpoint = {}" .format (self .idp .config .entityid ))
@@ -675,11 +679,18 @@ def _load_idp_dynamic_endpoints(self, context):
675679 :param context:
676680 :return: An idp server
677681 """
678- target_entity_id = context . target_entity_id_from_path ( )
682+ target_entity_id = self . _target_entity_id_from_path ( context . path )
679683 idp_conf_file = self ._load_endpoints_to_config (context .target_backend , target_entity_id )
680684 idp_config = IdPConfig ().load (idp_conf_file )
681685 return Server (config = idp_config )
682686
687+ def _target_entity_id_from_path (self , request_path ):
688+ path = request_path .lstrip ("/" )
689+ base_path = urlparse (self .base_url ).path .lstrip ("/" )
690+ if base_path and path .startswith (base_path ):
691+ path = path [len (base_path ):].lstrip ("/" )
692+ return path .split ("/" )[1 ]
693+
683694 def _load_idp_dynamic_entity_id (self , state ):
684695 """
685696 Loads an idp server with the entity id saved in state
@@ -705,7 +716,7 @@ def handle_authn_request(self, context, binding_in):
705716 :type binding_in: str
706717 :rtype: satosa.response.Response
707718 """
708- target_entity_id = context . target_entity_id_from_path ( )
719+ target_entity_id = self . _target_entity_id_from_path ( context . path )
709720 target_entity_id = urlsafe_b64decode (target_entity_id ).decode ()
710721 context .decorate (Context .KEY_TARGET_ENTITYID , target_entity_id )
711722
@@ -723,7 +734,7 @@ def _create_state_data(self, context, resp_args, relay_state):
723734 :rtype: dict[str, dict[str, str] | str]
724735 """
725736 state = super ()._create_state_data (context , resp_args , relay_state )
726- state ["target_entity_id" ] = context . target_entity_id_from_path ( )
737+ state ["target_entity_id" ] = self . _target_entity_id_from_path ( context . path )
727738 return state
728739
729740 def handle_backend_error (self , exception ):
@@ -758,13 +769,16 @@ def _register_endpoints(self, providers):
758769 """
759770 url_map = []
760771
772+ backend_providers = "|" .join (providers )
773+ base_path = urlparse (self .base_url ).path .lstrip ("/" )
774+ if base_path :
775+ base_path = base_path + "/"
761776 for endp_category in self .endpoints :
762777 for binding , endp in self .endpoints [endp_category ].items ():
763- valid_providers = "|^" .join (providers )
764- parsed_endp = urlparse (endp )
778+ endp_path = urlparse (endp ).path
765779 url_map .append (
766780 (
767- r"( ^{})/\S+/{}" .format (valid_providers , parsed_endp . path ),
781+ " ^{}({} )/\S+/{}$ " .format (base_path , backend_providers , endp_path ),
768782 functools .partial (self .handle_authn_request , binding_in = binding )
769783 )
770784 )
0 commit comments