@@ -21,45 +21,31 @@ class AuthAPIViews(APIResponseMixin):
2121 """API views for authentication"""
2222
2323 @staticmethod
24- def get_state_from_request (request ):
25- """Extract state from request URL or parameters"""
26- # Try to get state from query parameters first
27- state = request .GET .get ("state" )
28- if state :
29- return state .lower ()
30-
31- # Try to extract from URL path (e.g., /jurisdictions/illinois/)
32- path = request .path
33- if "/jurisdictions/" in path :
34- path_parts = path .split ("/jurisdictions/" )
35- if len (path_parts ) > 1 :
36- state_part = path_parts [1 ].split ("/" )[0 ]
37- if state_part :
38- return state_part .lower ()
39-
40- # Default to Illinois if no state found
41- return "illinois"
24+ def get_jurisdiction_from_request (request ):
25+ """Extract jurisdiction from request URL or parameters"""
26+ # Try to get jurisdiction from query parameters first
27+ jurisdiction = request .GET .get ("jurisdiction" )
28+ if jurisdiction :
29+ return jurisdiction .lower ()
30+ return None
4231
4332 @staticmethod
44- def get_tyler_token (request , state = None ):
33+ def get_tyler_token (request , jurisdiction = None ):
4534 """Helper method to retrieve Tyler token from various sources"""
46- if state is None :
47- state = AuthAPIViews .get_state_from_request (request )
35+ if jurisdiction is None :
36+ jurisdiction = AuthAPIViews .get_jurisdiction_from_request (request )
4837
4938 auth_tokens = request .session .get ("auth_tokens" , {})
5039 logger .debug (f"Auth tokens in session: { auth_tokens } " )
5140
5241 # Try different Tyler token key formats
5342 tyler_token = (
54- auth_tokens .get (f"TYLER-TOKEN-{ state .upper ()} " )
55- or auth_tokens .get (f"tyler_token_{ state } " )
56- or auth_tokens .get (f"tyler-token-{ state } " )
43+ auth_tokens .get (f"TYLER-TOKEN-{ jurisdiction .upper ()} " )
44+ or auth_tokens .get (f"tyler_token_{ jurisdiction } " )
45+ or auth_tokens .get (f"tyler-token-{ jurisdiction } " )
5746 )
5847
59- if tyler_token :
60- return tyler_token
61-
62- return None
48+ return tyler_token
6349
6450 @staticmethod
6551 @require_http_methods (["POST" ])
@@ -107,25 +93,25 @@ def user_profile(request):
10793 """Get current user profile from external Suffolk eFile API"""
10894 try :
10995 try :
110- # Get state and Tyler token dynamically
111- state = AuthAPIViews .get_state_from_request (request )
112- tyler_token = AuthAPIViews .get_tyler_token (request , state )
96+ # Get jurisdiction and Tyler token dynamically
97+ jurisdiction = AuthAPIViews .get_jurisdiction_from_request (request )
98+ tyler_token = AuthAPIViews .get_tyler_token (request , jurisdiction )
11399 api_key = getattr (settings , "SUFFOLK_EFILE_API_KEY" , None )
114100
115101 headers = {
116102 "Content-Type" : "application/json" ,
117- "User-Agent" : f"{ state .title ()} -eFile-Client/1.0" ,
103+ "User-Agent" : f"{ jurisdiction .title ()} -eFile-Client/1.0" ,
118104 "X-API-Key" : api_key if api_key else "" ,
119105 }
120106
121107 # Add Tyler token if available
122108 if tyler_token :
123- headers [f"tyler-token-{ state } " ] = tyler_token
109+ headers [f"tyler-token-{ jurisdiction } " ] = tyler_token
124110 else :
125111 # Log that no token was found for debugging
126- logger .info ("No Tyler token found for state '%s' in Suffolk eFile API request" , state )
112+ logger .info ("No Tyler token found for state '%s' in Suffolk eFile API request" , jurisdiction )
127113
128- url = f"{ settings .EFSP_URL } /jurisdictions/{ state } /firmattorneyservice/firm"
114+ url = f"{ settings .EFSP_URL } /jurisdictions/{ jurisdiction } /firmattorneyservice/firm"
129115 logger .debug ("GET %s header keys=%s" , url , list (headers .keys ()))
130116 api_response = requests .get (url , headers = headers , timeout = 10 )
131117 logger .debug (
@@ -293,11 +279,11 @@ def external_auth(request):
293279 return AuthAPIViews .error_response ("Username and password required" )
294280
295281 # Authenticate with Suffolk eFile API
296- state = AuthAPIViews .get_state_from_request (request )
282+ jurisdiction = AuthAPIViews .get_jurisdiction_from_request (request )
297283 auth_response = requests .post (
298- f"{ settings .EFSP_URL } /jurisdictions/{ state } /auth/login" ,
284+ f"{ settings .EFSP_URL } /jurisdictions/{ jurisdiction } /auth/login" ,
299285 json = {"username" : username , "password" : password },
300- headers = {"Content-Type" : "application/json" , "User-Agent" : f"{ state .title ()} -eFile-Client/1.0" },
286+ headers = {"Content-Type" : "application/json" , "User-Agent" : f"{ jurisdiction .title ()} -eFile-Client/1.0" },
301287 )
302288
303289 if auth_response .status_code == 200 :
@@ -307,17 +293,17 @@ def external_auth(request):
307293 request .session ["auth_tokens" ] = {
308294 "access_token" : auth_data .get ("access_token" ),
309295 "refresh_token" : auth_data .get ("refresh_token" ),
310- f"tyler_token_{ state } " : auth_data .get (f"tyler_token_{ state } " ),
296+ f"tyler_token_{ jurisdiction } " : auth_data .get (f"tyler_token_{ jurisdiction } " ),
311297 "expires_in" : auth_data .get ("expires_in" ),
312- "state" : state , # Store the state for future reference
298+ "state" : jurisdiction , # Store the state for future reference
313299 }
314300
315301 return AuthAPIViews .success_response (
316302 {
317303 "authenticated" : True ,
318304 "user" : auth_data .get ("user" , {}),
319- "state" : state ,
320- "has_tyler_token" : f"tyler_token_{ state } " in auth_data ,
305+ "state" : jurisdiction ,
306+ "has_tyler_token" : f"tyler_token_{ jurisdiction } " in auth_data ,
321307 },
322308 "External authentication successful" ,
323309 )
@@ -364,12 +350,14 @@ def external_profile(request):
364350 def tyler_token (request ):
365351 """Get Tyler token and API key for external form submissions"""
366352 try :
367- # Get state and Tyler token dynamically
368- state = AuthAPIViews .get_state_from_request (request )
369- tyler_token = AuthAPIViews .get_tyler_token (request , state )
353+ # Get jurisdiction and Tyler token dynamically
354+ jurisdiction = AuthAPIViews .get_jurisdiction_from_request (request )
355+ tyler_token = AuthAPIViews .get_tyler_token (request , jurisdiction )
370356 api_key = getattr (settings , "SUFFOLK_EFILE_API_KEY" , None )
371357
372- return AuthAPIViews .success_response ({"tyler_token" : tyler_token , "api_key" : api_key , "state" : state })
358+ return AuthAPIViews .success_response (
359+ {"tyler_token" : tyler_token , "api_key" : api_key , "state" : jurisdiction }
360+ )
373361 except Exception as e :
374362 return AuthAPIViews .error_response (f"Error: { str (e )} " )
375363
@@ -378,28 +366,28 @@ def tyler_token(request):
378366 def payment_accounts (request ):
379367 """Get payment accounts from Suffolk eFile API with proper authentication"""
380368 try :
381- # Get state and Tyler token dynamically
382- state = AuthAPIViews .get_state_from_request (request )
383- tyler_token = AuthAPIViews .get_tyler_token (request , state )
369+ # Get jurisdiction and Tyler token dynamically
370+ jurisdiction = AuthAPIViews .get_jurisdiction_from_request (request )
371+ tyler_token = AuthAPIViews .get_tyler_token (request , jurisdiction )
384372 api_key = getattr (settings , "SUFFOLK_EFILE_API_KEY" , None )
385373
386374 headers = {
387375 "Content-Type" : "application/json" ,
388- "User-Agent" : f"{ state .title ()} -eFile-Client/1.0" ,
376+ "User-Agent" : f"{ jurisdiction .title ()} -eFile-Client/1.0" ,
389377 "X-API-Key" : api_key if api_key else "" ,
390378 }
391379
392380 # Add Tyler token if available
393381 if tyler_token :
394- headers [f"tyler-token-{ state } " ] = tyler_token
382+ headers [f"tyler-token-{ jurisdiction } " ] = tyler_token
395383 else :
396384 # Log that no token was found for debugging
397385 logger .info (
398386 "No Tyler token found for state '%s' in Suffolk eFile payment accounts request" ,
399- state ,
387+ jurisdiction ,
400388 )
401389
402- url = f"{ settings .EFSP_URL } /jurisdictions/{ state } /payments/payment-accounts/"
390+ url = f"{ settings .EFSP_URL } /jurisdictions/{ jurisdiction } /payments/payment-accounts/"
403391 logger .debug ("GET %s header keys=%s" , url , list (headers .keys ()))
404392 api_response = requests .get (url , headers = headers , timeout = 10 )
405393 logger .debug (
0 commit comments