@@ -161,6 +161,14 @@ def login_and_registration_form(request, initial_mode="login"):
161161 # Retrieve the form descriptions from the user API
162162 form_descriptions = _get_form_descriptions (request )
163163
164+ # Detect a running TPA pipeline early so it can guard against redirect loops below.
165+ saml_provider = False
166+ running_pipeline = pipeline .get (request )
167+ if running_pipeline :
168+ saml_provider , __ = third_party_auth .utils .is_saml_provider (
169+ running_pipeline .get ('backend' ), running_pipeline .get ('kwargs' )
170+ )
171+
164172 # Our ?next= URL may itself contain a parameter 'tpa_hint=x' that we need to check.
165173 # If present, we display a login page focused on third-party auth with that provider.
166174 third_party_auth_hint = None
@@ -172,9 +180,10 @@ def login_and_registration_form(request, initial_mode="login"):
172180 provider_id = next_args ['tpa_hint' ][0 ]
173181 tpa_hint_provider = third_party_auth .provider .Registry .get (provider_id = provider_id )
174182 if tpa_hint_provider :
175- if tpa_hint_provider .skip_hinted_login_dialog :
183+ if tpa_hint_provider .skip_hinted_login_dialog and not running_pipeline :
176184 # Forward the user directly to the provider's login URL when the provider is configured
177- # to skip the dialog.
185+ # to skip the dialog. Do not redirect if a TPA pipeline is already running, as that
186+ # would cause an infinite loop (e.g. new SAML users dispatched back to /login).
178187 if initial_mode == "register" :
179188 auth_entry = pipeline .AUTH_ENTRY_REGISTER
180189 else :
@@ -194,18 +203,6 @@ def login_and_registration_form(request, initial_mode="login"):
194203 # tpa_hint_provider is not available
195204 # AND
196205 # user is not coming from a SAML IDP.
197- saml_provider = False
198- running_pipeline = pipeline .get (request )
199- if running_pipeline :
200- backend_name = running_pipeline .get ('backend' )
201- if backend_name == 'tpa-saml' :
202- # Directly detect SAML backend to avoid registry lookup failures
203- # (e.g. when pipeline kwargs lack response['idp_name'] at this point).
204- saml_provider = True
205- else :
206- saml_provider , __ = third_party_auth .utils .is_saml_provider (
207- backend_name , running_pipeline .get ('kwargs' )
208- )
209206
210207 enterprise_customer = enterprise_customer_for_request (request )
211208
0 commit comments