Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
social_auth: Save authentication method information in the session.
Mateusz Mandera254ea4b0c852
diff --git a/zerver/views/auth.py b/zerver/views/auth.pyindex 3c3f29cfb13..23e3606ad9a 100644--- a/zerver/views/auth.py+++ b/zerver/views/auth.py@@ -339,6 +339,10 @@ def login_or_register_remote_user(request: HttpRequest, result: ExternalAuthResu* A zulip:// URL to send control back to the mobile or desktop apps if theyare doing authentication using the mobile_flow_otp or desktop_flow_otp flow."""++ for key, value in result.data_dict.get("params_to_store_in_authenticated_session", {}).items():+ request.session[key] = value+user_profile = result.user_profileif user_profile is None or user_profile.is_mirror_dummy:return register_remote_user(request, result)diff --git a/zproject/backends.py b/zproject/backends.pyindex 4b2c4939eb3..2556a538774 100644--- a/zproject/backends.py+++ b/zproject/backends.py@@ -1295,6 +1295,7 @@ class ExternalAuthDataDict(TypedDict, total=False):desktop_flow_otp: Optional[str]multiuse_object_key: strfull_name_validated: bool+ params_to_store_in_authenticated_session: Dict[str, str]class ExternalAuthResult:@@ -1797,6 +1798,7 @@ def social_auth_finish(full_name_validated=full_name_validated,mobile_flow_otp=mobile_flow_otp,desktop_flow_otp=desktop_flow_otp,+ params_to_store_in_authenticated_session=backend.get_params_to_store_in_authenticated_session(),)if user_profile is None:data_dict.update(dict(full_name=full_name, email=email_address))@@ -1875,6 +1877,13 @@ class SocialAuthMixin(ZulipAuthMixin, ExternalAuthMethod, BaseAuth):def should_auto_signup(self) -> bool:return False+ def get_params_to_store_in_authenticated_session(self) -> Dict[str, str]:+ """+ Specifies a dict of keys:values to be saved in the user's session+ after successfully authenticating.+ """+ return {"authentication_method": self.name}+@classmethoddef dict_representation(cls, realm: Optional[Realm] = None) -> List[ExternalAuthMethodDictT]:return [@@ -2701,6 +2710,11 @@ class SAMLAuthBackend(SocialAuthMixin, SAMLAuth):assert isinstance(auto_signup, bool)return auto_signup+ def get_params_to_store_in_authenticated_session(self) -> Dict[str, str]:+ idp_name = self.strategy.session_get("saml_idp_name")++ return {"authentication_method": f"saml:{idp_name}"}+def patch_saml_auth_require_messages_signed(auth: OneLogin_Saml2_Auth) -> None:"""