@@ -117,7 +117,7 @@ def register_endpoints(self, backend_names):
117
117
118
118
if self .enable_metadata_reload ():
119
119
url_map .append (
120
- ("^%s/%s$" % (self .name , "reload-metadata" ), self ._reload_metadata ))
120
+ ("^%s/%s$" % (self .endpoint_basepath , "reload-metadata" ), self ._reload_metadata ))
121
121
122
122
self .idp_config = self ._build_idp_config_endpoints (
123
123
self .config [self .KEY_IDP_CONFIG ], backend_names )
@@ -512,15 +512,19 @@ def _register_endpoints(self, providers):
512
512
"""
513
513
url_map = []
514
514
515
+ backend_providers = "|" .join (providers )
516
+ base_path = urlparse (self .base_url ).path .lstrip ("/" )
517
+ if base_path :
518
+ base_path = base_path + "/"
515
519
for endp_category in self .endpoints :
516
520
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
+ )
524
528
525
529
if self .expose_entityid_endpoint ():
526
530
logger .debug ("Exposing frontend entity endpoint = {}" .format (self .idp .config .entityid ))
@@ -676,11 +680,18 @@ def _load_idp_dynamic_endpoints(self, context):
676
680
:param context:
677
681
:return: An idp server
678
682
"""
679
- target_entity_id = context . target_entity_id_from_path ( )
683
+ target_entity_id = self . _target_entity_id_from_path ( context . path )
680
684
idp_conf_file = self ._load_endpoints_to_config (context .target_backend , target_entity_id )
681
685
idp_config = IdPConfig ().load (idp_conf_file )
682
686
return Server (config = idp_config )
683
687
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
+
684
695
def _load_idp_dynamic_entity_id (self , state ):
685
696
"""
686
697
Loads an idp server with the entity id saved in state
@@ -706,7 +717,7 @@ def handle_authn_request(self, context, binding_in):
706
717
:type binding_in: str
707
718
:rtype: satosa.response.Response
708
719
"""
709
- target_entity_id = context . target_entity_id_from_path ( )
720
+ target_entity_id = self . _target_entity_id_from_path ( context . path )
710
721
target_entity_id = urlsafe_b64decode (target_entity_id ).decode ()
711
722
context .decorate (Context .KEY_TARGET_ENTITYID , target_entity_id )
712
723
@@ -724,7 +735,7 @@ def _create_state_data(self, context, resp_args, relay_state):
724
735
:rtype: dict[str, dict[str, str] | str]
725
736
"""
726
737
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 )
728
739
return state
729
740
730
741
def handle_backend_error (self , exception ):
@@ -759,13 +770,16 @@ def _register_endpoints(self, providers):
759
770
"""
760
771
url_map = []
761
772
773
+ backend_providers = "|" .join (providers )
774
+ base_path = urlparse (self .base_url ).path .lstrip ("/" )
775
+ if base_path :
776
+ base_path = base_path + "/"
762
777
for endp_category in self .endpoints :
763
778
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
766
780
url_map .append (
767
781
(
768
- r"( ^{})/\S+/{}" .format (valid_providers , parsed_endp . path ),
782
+ " ^{}({} )/\S+/{}$ " .format (base_path , backend_providers , endp_path ),
769
783
functools .partial (self .handle_authn_request , binding_in = binding )
770
784
)
771
785
)
0 commit comments