@@ -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 )
@@ -512,15 +512,19 @@ def _register_endpoints(self, providers):
512512 """
513513 url_map = []
514514
515+ backend_providers = "|" .join (providers )
516+ base_path = urlparse (self .base_url ).path .lstrip ("/" )
517+ if base_path :
518+ base_path = base_path + "/"
515519 for endp_category in self .endpoints :
516520 for binding , endp in self .endpoints [endp_category ].items ():
517- valid_providers = ""
518- for provider in providers :
519- valid_providers = "{}|^{}" . format ( valid_providers , provider )
520- valid_providers = valid_providers . lstrip ( "|" )
521- parsed_endp = urlparse ( endp )
522- url_map . append (( "(%s)/%s$" % ( valid_providers , parsed_endp . path ),
523- functools . partial ( self . handle_authn_request , binding_in = binding )) )
521+ endp_path = urlparse ( endp ). path
522+ url_map . append (
523+ (
524+ "^{}({})/{}$" . format ( base_path , backend_providers , endp_path ),
525+ functools . partial ( self . handle_authn_request , binding_in = binding )
526+ )
527+ )
524528
525529 if self .expose_entityid_endpoint ():
526530 logger .debug ("Exposing frontend entity endpoint = {}" .format (self .idp .config .entityid ))
@@ -676,11 +680,18 @@ def _load_idp_dynamic_endpoints(self, context):
676680 :param context:
677681 :return: An idp server
678682 """
679- target_entity_id = context . target_entity_id_from_path ( )
683+ target_entity_id = self . _target_entity_id_from_path ( context . path )
680684 idp_conf_file = self ._load_endpoints_to_config (context .target_backend , target_entity_id )
681685 idp_config = IdPConfig ().load (idp_conf_file )
682686 return Server (config = idp_config )
683687
688+ def _target_entity_id_from_path (self , request_path ):
689+ path = request_path .lstrip ("/" )
690+ base_path = urlparse (self .base_url ).path .lstrip ("/" )
691+ if base_path and path .startswith (base_path ):
692+ path = path [len (base_path ):].lstrip ("/" )
693+ return path .split ("/" )[1 ]
694+
684695 def _load_idp_dynamic_entity_id (self , state ):
685696 """
686697 Loads an idp server with the entity id saved in state
@@ -706,7 +717,7 @@ def handle_authn_request(self, context, binding_in):
706717 :type binding_in: str
707718 :rtype: satosa.response.Response
708719 """
709- target_entity_id = context . target_entity_id_from_path ( )
720+ target_entity_id = self . _target_entity_id_from_path ( context . path )
710721 target_entity_id = urlsafe_b64decode (target_entity_id ).decode ()
711722 context .decorate (Context .KEY_TARGET_ENTITYID , target_entity_id )
712723
@@ -724,7 +735,7 @@ def _create_state_data(self, context, resp_args, relay_state):
724735 :rtype: dict[str, dict[str, str] | str]
725736 """
726737 state = super ()._create_state_data (context , resp_args , relay_state )
727- state ["target_entity_id" ] = context . target_entity_id_from_path ( )
738+ state ["target_entity_id" ] = self . _target_entity_id_from_path ( context . path )
728739 return state
729740
730741 def handle_backend_error (self , exception ):
@@ -759,13 +770,16 @@ def _register_endpoints(self, providers):
759770 """
760771 url_map = []
761772
773+ backend_providers = "|" .join (providers )
774+ base_path = urlparse (self .base_url ).path .lstrip ("/" )
775+ if base_path :
776+ base_path = base_path + "/"
762777 for endp_category in self .endpoints :
763778 for binding , endp in self .endpoints [endp_category ].items ():
764- valid_providers = "|^" .join (providers )
765- parsed_endp = urlparse (endp )
779+ endp_path = urlparse (endp ).path
766780 url_map .append (
767781 (
768- r"( ^{})/\S+/{}" .format (valid_providers , parsed_endp . path ),
782+ " ^{}({} )/\S+/{}$ " .format (base_path , backend_providers , endp_path ),
769783 functools .partial (self .handle_authn_request , binding_in = binding )
770784 )
771785 )
0 commit comments