From 34efab915732fff104b3a69dcf131d09651f2bc3 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 6 Feb 2018 14:36:56 -0800 Subject: [PATCH] auth: Report to mobile apps the availability of RemoteUserBackend. This is necessary for mobile apps to do the right thing when only RemoteUserBackend is enabled, namely, directly redirect to the third-party SSO auth site as soon as the user enters the server URL (no need to display a login form, since it'll be useless). --- zerver/tests/test_auth_backends.py | 7 ++++++- zerver/views/auth.py | 4 +++- zproject/backends.py | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index d5064d9b65..0193f46f47 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -1320,6 +1320,7 @@ class FetchAuthBackends(ZulipTestCase): ('email', check_bool), ('ldap', check_bool), ('dev', check_bool), + ('remoteuser', check_bool), ('password', check_bool), ])), ('email_auth_enabled', check_bool), @@ -1353,7 +1354,7 @@ class FetchAuthBackends(ZulipTestCase): data = result.json() self.assertEqual(set(data.keys()), {'msg', 'password', 'github', 'google', 'email', 'ldap', - 'dev', 'result', 'zulip_version'}) + 'dev', 'result', 'remoteuser', 'zulip_version'}) for backend in set(data.keys()) - {'msg', 'result', 'zulip_version'}: self.assertTrue(isinstance(data[backend], bool)) @@ -1371,6 +1372,7 @@ class FetchAuthBackends(ZulipTestCase): 'dev': True, 'email': False, 'ldap': False, + 'remoteuser': False, 'result': 'success', 'zulip_version': ZULIP_VERSION, }) @@ -1387,6 +1389,7 @@ class FetchAuthBackends(ZulipTestCase): 'google': True, 'email': False, 'ldap': False, + 'remoteuser': False, 'dev': True, 'result': 'success', 'zulip_version': ZULIP_VERSION, @@ -1412,6 +1415,7 @@ class FetchAuthBackends(ZulipTestCase): 'google': False, 'email': False, 'ldap': False, + 'remoteuser': False, 'dev': True, 'result': 'success', 'zulip_version': ZULIP_VERSION, @@ -1433,6 +1437,7 @@ class FetchAuthBackends(ZulipTestCase): 'github': False, 'google': False, 'email': False, + 'remoteuser': False, 'ldap': False, 'dev': True, 'result': 'success', diff --git a/zerver/views/auth.py b/zerver/views/auth.py index f236f9b425..46392eea74 100644 --- a/zerver/views/auth.py +++ b/zerver/views/auth.py @@ -35,7 +35,8 @@ from zerver.models import PreregistrationUser, UserProfile, remote_user_to_email from zerver.signals import email_on_new_login from zproject.backends import password_auth_enabled, dev_auth_enabled, \ github_auth_enabled, google_auth_enabled, ldap_auth_enabled, \ - ZulipLDAPConfigurationError, ZulipLDAPAuthBackend, email_auth_enabled + ZulipLDAPConfigurationError, ZulipLDAPAuthBackend, email_auth_enabled, \ + remote_auth_enabled from version import ZULIP_VERSION import hashlib @@ -698,6 +699,7 @@ def get_auth_backends_data(request: HttpRequest) -> Dict[str, Any]: "email": email_auth_enabled(realm), "github": github_auth_enabled(realm), "google": google_auth_enabled(realm), + "remoteuser": remote_auth_enabled(realm), "ldap": ldap_auth_enabled(realm), } diff --git a/zproject/backends.py b/zproject/backends.py index e81ae99acc..afe9e05d28 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -63,6 +63,9 @@ def google_auth_enabled(realm: Optional[Realm]=None) -> bool: def github_auth_enabled(realm: Optional[Realm]=None) -> bool: return auth_enabled_helper(['GitHub'], realm) +def remote_auth_enabled(realm: Optional[Realm]=None) -> bool: + return auth_enabled_helper(['RemoteUser'], realm) + def any_oauth_backend_enabled(realm: Optional[Realm]=None) -> bool: """Used by the login page process to determine whether to show the 'OR' for login with Google"""