Skip to main content

Custom integration for django-otp package

Project description

Zweifach (german for “two times”) is an app to make integration of django-otp a bit more biased.

Integration of two factor auth is enforced by a middleware which will ensure two things:

  • make sure a user who is required to enable 2FA for its account will be redirected to the setup-view until setup is done.

  • make sure a user who has 2FA enabled will be redirected to verify-view for token input after login until verified.

Quickstart

  • Install packages by running ‘pip install zweifach django-otp qrcode’

  • Add ‘zweifach’ to INSTALLED_APPS.

  • Add ‘zweifach.middleware.ZweifachMiddleware’ to MIDDLEWARE, after AuthenticationMiddleware.

  • Inlcude ‘zweifach.urls’ somewhere in your url-config.

  • Configure django-otp as described further down below

Settings

settings.ZWEIFACH_AUTH_REQUIRED

default: []

A list of checks which determine, if a user needs 2FA to use its account.

examaple:

ZWEIFACH_AUTH_REQUIRED = [
    lambda user: user.is_staff,  # all staff unsers must use two factor auth
    lambda user: '2fa' in user.groups.values_list("name", flat=True),  # all users in group '2fa' must use two factor auth
]

settings.ZWEIFACH_URL_EXCLUDES

default: []

A list of url which are always accessible without 2FA. Verify and Setup views are always excluded as well as settings.LOGIN_URL and the admin login view, if admin is enabled.

example:

ZWEIFACH_URL_EXCLUDES = [
    '/imprint/',
    '/faq/how-to-setup-2fa/',
]

Note: If a url is accessible without login, it can of course still be viewed without any 2FA interaction.

Notes about django-otp configuration

A compatible installation of django-otp should be setup as follows:

Add to INSTALLED_APPS:

'django_otp',
'django_otp.plugins.otp_totp',
'django_otp.plugins.otp_static',

Add to MIDDLEWARE (between AuthenticationMiddleware and ZweifachMiddleware):

'django_otp.middleware.OTPMiddleware'

Configure issuer:

OTP_TOTP_ISSUER = 'MyProject'

Usage

To generate static recovery tokens (also useful for first login on freshly installed systems) use:

./manage.py addstatictoken <username>

Development

Ensure basic code style with:

tox

Build package with:

python3 -m build

Upload package to PyPI:

python3 -m twine upload dist/zweifach-x.x.x*

Project details


Download files

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

Source Distribution

zweifach-1.0.3.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

zweifach-1.0.3-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file zweifach-1.0.3.tar.gz.

File metadata

  • Download URL: zweifach-1.0.3.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.6

File hashes

Hashes for zweifach-1.0.3.tar.gz
Algorithm Hash digest
SHA256 e654839b218d1140f247d02a1cc8721ff69e697202814eb7465bf8f6d3ae980c
MD5 ca0ed0a55b4d73a7dbed832e5ed43a6e
BLAKE2b-256 851f8093eeec7196bab205f6500018bef6084a059f92c2585988d11d708f3e33

See more details on using hashes here.

File details

Details for the file zweifach-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: zweifach-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.6

File hashes

Hashes for zweifach-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ccd548e398aedfdc551684d440c216b13df7f0aae424d7128bd5ca6bbb325d9d
MD5 cb45195aab8e9516b2e33da79db1b7c1
BLAKE2b-256 6395812ccd3ba83c32a3c9418ec4cf6b09a17c7737af53e04c63f1db7cbed5f9

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