mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	auth: Add ExternalAuthResult to manage data in authentication flows.
This new type eliminates a bunch of messy code that previously involved passing around long lists of mixed positional keyword and arguments, instead using a consistent data object for communicating about the state of an external authentication (constructed in backends.py). The result is a significantly more readable interface between zproject/backends.py and zerver/views/auth.py, though likely more could be done. This has the side effect of renaming fields for internally passed structures from name->full_name, next->redirect_to; this results in most of the test codebase changes. Modified by tabbott to add comments and collaboratively rewrite the initialization logic.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							3f69500765
						
					
				
				
					commit
					f1ec02b40a
				
			@@ -23,7 +23,6 @@ from zerver.tornado import event_queue
 | 
			
		||||
from zerver.tornado.handlers import allocate_handler_id
 | 
			
		||||
from zerver.worker import queue_processors
 | 
			
		||||
from zerver.lib.integrations import WEBHOOK_INTEGRATIONS
 | 
			
		||||
from zerver.views.auth import get_login_data
 | 
			
		||||
 | 
			
		||||
from zerver.models import (
 | 
			
		||||
    get_realm,
 | 
			
		||||
@@ -36,6 +35,8 @@ from zerver.models import (
 | 
			
		||||
    UserProfile,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
from zproject.backends import ExternalAuthResult, ExternalAuthDataDict
 | 
			
		||||
 | 
			
		||||
if TYPE_CHECKING:
 | 
			
		||||
    # Avoid an import cycle; we only need these for type annotations.
 | 
			
		||||
    from zerver.lib.test_classes import ZulipTestCase, MigrationsTestCase
 | 
			
		||||
@@ -445,10 +446,10 @@ def write_instrumentation_reports(full_suite: bool, include_webhooks: bool) -> N
 | 
			
		||||
                print("   %s" % (untested_pattern,))
 | 
			
		||||
            sys.exit(1)
 | 
			
		||||
 | 
			
		||||
def load_subdomain_token(response: HttpResponse) -> Dict[str, Any]:
 | 
			
		||||
def load_subdomain_token(response: HttpResponse) -> ExternalAuthDataDict:
 | 
			
		||||
    assert isinstance(response, HttpResponseRedirect)
 | 
			
		||||
    token = response.url.rsplit('/', 1)[1]
 | 
			
		||||
    data = get_login_data(token, should_delete=False)
 | 
			
		||||
    data = ExternalAuthResult(login_token=token, delete_stored_data=False).data_dict
 | 
			
		||||
    assert data is not None
 | 
			
		||||
    return data
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user