Authentication in the development environment

This page documents special notes that are useful for configuring Zulip's various authentication methods for testing in a development environment.

Many of these authentication methods involve a complex interaction between Zulip, an external service, and the user's browser. Because browsers can (rightly!) be picky about the identity of sites you interact with, the preferred way to set up authentication methods in a development environment is provide secret keys so that you can go through the real flow.

The steps to do this are a variation of the steps discussed in the production documentation, including the comments in zproject/prod_settings_template.py. The differences here are driven by the fact that dev_settings.py is in Git, so it is inconvenient for local settings configuration. As a result, in the development environment, we allow setting certain settings in the untracked file zproject/dev-secrets.conf (which is also serves as /etc/zulip/zulip-secrets.conf).

Below, we document the procedure for each of the major authentication methods supported by Zulip.

Email and password

Zulip's default EmailAuthBackend authenticates users by verifying control over their email address, and then allowing them to set a password for their account. There are two development environment details worth understanding:

Google

GitHub

GitLab

Apple

SAML

When SSL is required

Some OAuth providers (such as Facebook) require HTTPS on the callback URL they post back to, which isn't supported directly by the Zulip development environment. If you run a remote Zulip development server, we have instructions for an nginx reverse proxy with SSL that you can use for your development efforts.

Testing LDAP in development

Before Zulip 2.0, one of the more common classes of bug reports with Zulip's authentication was users having trouble getting LDAP authentication working. The root cause was because setting up a local LDAP server for development was difficult, which meant most developers were unable to work on fixing even simple issues with it.

We solved this problem for our unit tests long ago by using the popular fakeldap library. And in 2018, we added convenient support for using fakeldap in the Zulip development environment as well, so that you can go through all the actual flows for LDAP configuration.

Testing avatar and custom profile field synchronization

The fakeldap LDAP directories we use in the development environment are generated by the code in zerver/lib/dev_ldap_directory.py, and contain data one might want to sync, including avatars and custom profile fields.

We also have configured AUTH_LDAP_USER_ATTR_MAP in zproject/dev_settings.py to sync several of those fields. For example:

Automated testing

For our automated tests, we generally configure custom LDAP data for each individual test, because that generally means one can understand exactly what data is being used in the test without looking at other resources. It also gives us more freedom to edit the development environment directory without worrying about tests.

Two factor authentication

Zulip uses django-two-factor-auth as a beta 2FA integration.

To enable 2FA, set TWO_FACTOR_AUTHENTICATION_ENABLED in settings to True, then log in to Zulip and add an OTP device from the settings page. Once the device is added, password based authentication will ask for a one-time-password. In the development environment, this one-time-password will be printed to the console when you try to log in. Just copy-paste it into the form field to continue.

Direct development logins don't prompt for 2FA one-time-passwords, so to test 2FA in development, make sure that you log in using a password. You can get the passwords for the default test users using ./manage.py print_initial_password.

Password form implementation

By default, Zulip uses autocomplete=off for password fields where we enter the current password, and autocomplete="new-password" for password fields where we create a new account or change the existing password. This prevents the browser from auto-filling the existing password.

Visit https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete for more details.