Skip to main content

Make your authentication logs more easy with django-auth-audit

Please note

django-auth-audit still an experimental project that originated as a feature in one of my professional projects. Due to the specific requirements and lack of existing GitHub repositories targeting this particular situation, I decided to create it as a separate project. As a result, the app is still in its early stages and may undergo frequent updates and improvements. Feedback and contributions are welcome.

Introduction

django-auth-audit is a Django reusable app that provides functionality for tracking user authentication events, such as logins,logouts,password rest rate limit ... It allows you to define custom mixins that override specific CRUD methods in your target class, send signals, and handle the flow back to your target class. Additionally, django-auth-audit includes a pre-defined mixins,that can be used to send signals and create authentication logs.

Installation

To install django-auth-audit, follow these steps:

  1. Ensure you have Django installed in your project. If not, you can install it using pip:
pip install django

Download the django-auth-audit package from the GitHub repository or install it using pip:

pip install django-auth-audit

Add django-auth-audit to the INSTALLED_APPS setting in your Django project's settings.py file:

INSTALLED_APPS = [
   ...
   'django-auth-audit',
   ...
]

Run the database migrations to create the necessary tables for the app:

python manage.py migrate django-auth-audit

Usage

django-auth-audit allows you to create custom mixins that override specific CRUD methods in your target class, send signals, and handle the flow back to your target class. Here's an example:

from dj_auth_audit.mixins import FailedResetEmailSignalMixin

class CustomPasswordResetView(FailedResetEmailSignalMixin, PasswordResetView):
    class_name = 'PasswordResetView'
    serializer_class = CustomPasswordResetSerializer
    throttle_scope = 'reset_password_rate'

In this example, the CustomPasswordResetView class inherits from FailedResetEmailSignalMixin and PasswordResetView. The FailedResetEmailSignalMixin sends a signal and creates an authentication log in the database, indicating the time of the sent reset email and the user who requested the password reset. If the user reaches the rate limit, another signal is triggered to indicate that the user has exceeded the password reset rate.

The FailedResetEmailSignalMixin is hooked with the POST and throttled methods, which are typically defined in the target class. To use this mixin, you need to define the class_name attribute in the subclass alongside with the self.user to define the actor.

Note

django-auth-audit has a built-in mixin for all basic authentication logs you will need ,inclusing but not limited to : Login , Logout,password change,password reset,verfication email ... and if you define a throttle scope on the subclass , you will get rate limit signal the user have exceeded the allowed request rate.

You can also define your own mixin by inheriting from AbstractSignalMixin in the mixin.py file.

Note: The FailedResetEmailSignalMixin or any other mixin will raise an exception if:

  • class_name is not defined.
  • The target class doesn't have any of the required methods for sending requests (POST,GET...)
  • The self.user is not defined. Please refer to mixin.py for more information on creating custom mixins and using the provided mixins.

Contributing

If you'd like to contribute to this project, please follow these guidelines:

Fork the repository on GitHub. Create a new branch from the master branch for your feature or bug fix. Make your changes and ensure they are properly tested. Commit your changes with clear and descriptive commit messages. Push your branch to your forked repository. Submit a pull request to the master branch of the this repository. Please refer to the Contribution Guidelines for more information.

License

django-auth-audit is released under the MIT License. See the LICENSE file for more details.

Support

If you encounter any issues or have questions, please open an issue on the GitHub repository.

History

0.1.0 (2023-07-16) ++++++++++++++++++

  • First release on PyPI.

Metadata

Release files for django-auth-audit 0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-auth-audit 0.0
File Size Uploaded
django-auth-audit-0.0.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-auth-audit 0.0
File Interpreter ABI Platform
django_auth_audit-0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 25.6 kB

Release files / django-auth-audit-0.0.tar.gz

Download URL django-auth-audit-0.0.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
21fc1b2dce1cb33a49bcae666f5098d782b01cb0b8763e9c4b08bddd8eb0cce9
BLAKE2b-256 checksum
How to use checksums
da0c7f034aa92db17ceaafa173a473e62ba1ae5d9c05f20a2920eb5e22c05bdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.0

Release files / django_auth_audit-0.0-py2.py3-none-any.whl

Download URL django_auth_audit-0.0-py2.py3-none-any.whl
Size 13.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e217db2f6cc33f8b5240e4d423f42e146c97d925e9ddbf84b8df75e7ef47acac
BLAKE2b-256 checksum
How to use checksums
f40045668f34644c118e9f4579f05bca3d2da8ecde1dcad7dad702a611c1977c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page