Skip to main content

A pluggable framework for adding two-factor authentication to Django using one-time passwords.

Project description

PyPI Documentation Source

This project makes it easy to add support for one-time passwords (OTPs) to Django. It can be integrated at various levels, depending on how much customization is required. It integrates with django.contrib.auth, although it is not a Django authentication backend. The primary target is developers wishing to incorporate OTPs into their Django projects as a form of two-factor authentication.

Several simple OTP plugins are included and more are available separately. This package also includes an implementation of OATH HOTP and TOTP for convenience, as these are standard OTP algorithms used by multiple plugins.

If you’re looking for a higher-level or more opinionated solution, you might be interested in django-two-factor-auth.

Status

This project is stable and maintained, but is no longer actively used by the author and is not seeing much ongoing investment. Anyone interested in taking over aspects of the project should contact me.

Well-formed issues and pull requests are welcome, but please see the Contributing section of the README first.

The Future

Once upon a time, everything was usernames and passwords. Or even in the case of other authentication mechanisms, a user was either authenticated or not (anonymous in Django’s terminology). Then there was two-factor authentication, which could simply be an implementation detail in a binary authentication state, but could also imply levels or degrees of authentication.

These days, it’s increasingly common to see sites with more nuanced authentication state. A site might remember who you are forever—so you’re not anonymous—but if you try to do anything private, you have to re-authenticate. You may be able to choose from among all of the authentication mechanisms you have configured, or only from some of them. Specific mechanisms may be required for specific actions, such as using your U2F device to access your U2F settings.

In short, the world seems to be moving beyond the assumptions that originally informed Django’s essential authentication design. If I were still investing in Django generally, I would probably start a new multi-factor authentication project that would reflect these changes. It would incorporate the idea that a user may be authenticated by various combinations of mechanisms at any time and that different combinations may be required to satisfy diverse authorization requirements across the site. It would most likely try to disentangle authentication persistence from sessions, at least to some extent. Many sites would not require all of this flexibility, but it would open up possibilities for better experiences by not asking users for more than we require at any point.

If anyone has a mind to take on a project like this, I’d be happy to offer whatever advice or lessons learned that I can.

Development

Development dependencies are defined in the Pipfile; use pipenv to set up a suitable shell.

The tests in tox.ini cover a representative sample of supported Python and Django versions, as well as running flake8 and isort for linting and style consistency. Please run tox before checking in and sending a pull request.

Contributing

As mentioned above, this project is stable and mature. Issues and pull requests are welcome for important bugs and improvements. For non-trivial changes, it’s often a good idea to start by opening an issue to track the need for a change and then optionally open a pull request with a proposed resolution. Issues and pull requests should also be focused on a single thing. Pull requests that bundle together a bunch of loosely related commits are unlikely to go anywhere.

Another good rule of thumb—for any project, but especially a mature one—is to keep changes as simple as possible. In particular, there should be a high bar for adding new dependencies. Although it can’t be ruled out, it seems highly unlikely that a new runtime dependency will ever be added. New testing dependencies are more likely, but only if there’s no other way to address an important need.

If there’s a development tool that you’d like to use with this project, the first step is to try to update config files (setup.cfg or similar) to integrate the tool with the existing code. A bit of configuration glue for popular tools should always be safe. If that’s not possible, we can consider modifying the code to be compatible with a broader range of tools (without breaking any existing compatibilities). Only as a last resort would a new testing or development tool be incorporated into the project as a dependency.

It’s also good to remember that writing the code is typically the least part of the work. This is true for software development in general, but especially a small stable project like this. The bulk of the work is in understanding the problem, determining the desired attributes of a solution, researching and evaluating alternatives, writing documentation, designing a testing strategy, etc. Writing the code itself tends to be a minor matter that emerges from that process.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-otp-1.1.0.tar.gz (61.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_otp-1.1.0-py3-none-any.whl (59.7 kB view details)

Uploaded Python 3

File details

Details for the file django-otp-1.1.0.tar.gz.

File metadata

  • Download URL: django-otp-1.1.0.tar.gz
  • Upload date:
  • Size: 61.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.12

File hashes

Hashes for django-otp-1.1.0.tar.gz
Algorithm Hash digest
SHA256 44b7dfbf0fb10223f708fa5c0ec182c248e1c251bb35a872375fcd8c29615f17
MD5 5c23741a300fc42f44fd61ca70913b11
BLAKE2b-256 81bf9b67879c49c625f8888a4aa044ed3a7d10cf3b2e58dc71a2f05c929ea50b

See more details on using hashes here.

File details

Details for the file django_otp-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_otp-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 59.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.12

File hashes

Hashes for django_otp-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d19da92a825a1387c86d2e529418efea0f9b7025d882d2d3c1d05b958cf55fc5
MD5 4f15005916680fabce11a1df64b01b09
BLAKE2b-256 beaac6aa7dd4211bd6505bc2a35c4cbcbda68808323b26a573c65eacaaa150c6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page