Skip to main content

REST Multi-factor authentication package for Django

Project description

https://cybersecurity-excellence-awards.com/wp-content/uploads/2021/06/badges_2022_Silver.png
https://github.com/merixstudio/django-trench/actions/workflows/django-package.yml/badge.svg https://codecov.io/gh/merixstudio/django-trench/branch/master/graph/badge.svg?token=U4yDiXUDkb https://readthedocs.org/projects/django-trench/badge/?version=latest https://img.shields.io/pypi/v/django-trench-reboot
django-trench provides a set of REST API endpoints to supplement django-rest-framework with multi-factor authentication (MFA, 2FA). It supports both standard built-in authentication methods, as well as JWT (JSON Web Token).

We deliver a couple of sample secondary authentication methods including sending OTP based code by:
  • E-mail

  • SMS / text

  • 3rd party mobile apps

  • YubiKey

Developers can easily add their own authentication backends supporting any communication channel.

This is a fork of django_trench. As this package has gone unmaintained for some time, we have decided to maintain a temporary package in order to provide support for Django 4.2 and beyond (if necessary).

Features

  • Easily pluggable and compatible with django-rest-framework

  • Allows user to pick an additional authentication method from range of backends defined by a developer. Read more: backends

  • Comes out of a box with email, SMS, mobile apps and YubiKey support

Supported versions

  • Python 3.10, 3.11, 3.12, 3.13

  • Django 4.2, 5.0, 5.1, 5.2

  • Django REST Framework 3.10, 3.11, 3.12, 3.13, 3.14, 3.15

If you are going to use JWT authentication:

Quick Start

  1. Install the package using pip:

pip install django-trench

or add it to your requirements file.

  1. Add trench library to INSTALLED_APPS in your app settings file:

INSTALLED_APPS = (
    ...,
    'rest_framework',
    'rest_framework.authtoken',  # In case of implementing Token Based Authentication
    ...,
    'trench',
)
  1. Run migrations

Read further in: installation.

Translation

Trench uses Transifex service to translate our package into other languages.

We will appreciate your help with translation.

https://www.transifex.com/merixstudio/django-trench/dashboard/

Local development

  1. Clone the repo.

  2. Crete virtual environment named e.g. .venv:

    virtualenv .venv
  3. Activate the virtual environment:

    source .venv/bin/activate
  4. Install dependencies:

    pip install black mypy
    pip install -r testproject/requirements.txt
  5. Set environment variables:

    export PYTHONPATH=./testproject
    export DJANGO_SETTINGS_MODULE=settings
    export SECRET_KEY=YOURsecretGOEShere
  6. Create a symbolic link to the trench/ module inside the testproject/ directory to emulate the trench package being installed.

    # make sure you run this command from the root directory of this project
    ln -s $(pwd)/trench/ $(pwd)/testproject/trench
  7. Check whether the tests are passing:

    pytest --cov=testproject/trench testproject/tests/

Remember - anytime you change something in the django-trench source code you need to re-build and re-install the package (steps 6-7) for the changes to be present during e.g. running the tests.

  1. [OPTIONAL] To make the tests run faster you can try to execute them in parallel.

    To do so you need to install the pytest-xdist package and run the tests with additional parameter of -n 8 where 8 stands for the number of threads that will be spawned for executing the tests. Depending on the machine you’re using using this tool can speed up the test execution process up to 5 times.

    pytest -n 8 --cov=testproject/trench testproject/tests/

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

django_trench_reboot-0.3.10.tar.gz (38.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_trench_reboot-0.3.10-py3-none-any.whl (45.8 kB view details)

Uploaded Python 3

File details

Details for the file django_trench_reboot-0.3.10.tar.gz.

File metadata

  • Download URL: django_trench_reboot-0.3.10.tar.gz
  • Upload date:
  • Size: 38.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.24

File hashes

Hashes for django_trench_reboot-0.3.10.tar.gz
Algorithm Hash digest
SHA256 c9c996ba0d94c0c9abaf19f662c1f4d2f6784b5999e63d841aeaf88b260a5fa8
MD5 a06a17b1f513081447537496c8eec247
BLAKE2b-256 9a62589d8fba6ffb37cbaf4dcb5d5b82e73fd832aabf2f077bf662c719359ab5

See more details on using hashes here.

File details

Details for the file django_trench_reboot-0.3.10-py3-none-any.whl.

File metadata

File hashes

Hashes for django_trench_reboot-0.3.10-py3-none-any.whl
Algorithm Hash digest
SHA256 9ad26e4b4284ebef06213e71b7ff933c90a5c4c93ddb71e805cda3effbd25461
MD5 bdfeb96d63fcb4b1912deb24d656b276
BLAKE2b-256 51d890eb8bdaf281a27d95fb02149a8e2319dee3e3d91f079dfdc87d941a038f

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