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

This version

1.0.5

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.0.5.tar.gz (59.0 kB view details)

Uploaded Source

Built Distribution

django_otp-1.0.5-py3-none-any.whl (58.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-otp-1.0.5.tar.gz
  • Upload date:
  • Size: 59.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.10

File hashes

Hashes for django-otp-1.0.5.tar.gz
Algorithm Hash digest
SHA256 cc657a0e7266cda6ab42f861bdc3840ed24f7e441bc7f249916174dd1a6375a0
MD5 5fe29eb14ef6dbf93428298f4d05d4e1
BLAKE2b-256 f52c349c2e85e2fcdc80dd8bea57c6c523522a5884344674c59c50f73401502a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_otp-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 58.0 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.10

File hashes

Hashes for django_otp-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 75a815747a0542cc5442e3a6396dfd272c49a0866bee2149ac57ecc36ddd3961
MD5 23169f1d6a097d67582a52ca0c38fb53
BLAKE2b-256 a8cc95acecdd15fdebd63ecf1229b862643e5267e98e0b42c91d67a5456fee5c

See more details on using hashes here.

Supported by

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