Skip to main content

Django Auth IP Whitelist is a module for identity verification in Django applications, allowing login via IP address and offering whitelist functionality.

Project description

django-auth-ipwhitelist

https://img.shields.io/pypi/v/django-auth-ipwhitelist.svg

Django Auth IP Whitelist is a module for identity verification in Django applications, allowing login via IP address and offering whitelist functionality.

This module enables users to authenticate themselves automatically using their IP address, eliminating the need for traditional username and password login methods. Additionally, it includes whitelist functionality to prohibit users outside the whitelist, enhancing security and control. By combining IP address login with whitelist capabilities, this module provides a simple, secure, and efficient identity verification mechanism for Django applications.

Installation

Install useing pip:
pip install django-auth-ipwhitelist

Configuration

Add django_auth_ipwhitelist to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [
     ...
     'django_auth_ipwhitelist',
]
Add django_auth_ipwhitelist.middleware.AuthIPWhitelistMiddleware to your MIDDLEWARE setting like this:
MIDDLEWARE = [
    ...
    'django_auth_ipwhitelist.middleware.IPWhitelistMiddleware',
]
Add django_auth_ipwhitelist to your AUTHENTICATION_BACKENDS setting like this:
AUTHENTICATION_BACKENDS = [
    ...
    'django_auth_ipwhitelist.backends.IPAuthenticationBackend',
]
Create authipwhitelist database tables by running the following command:
python manage.py migrate django_auth_ipwhitelist
If you need to add default IP addresses to the whitelist, for example, for logging into the Django admin using the default address, you can achieve this by the following settings in settings.py. By default, 127.0.0.1 is already set as default whitelist addresses.
AUTH_IP_WHITELIST = {
    'ALLOWED_WHITELISTED_HOSTS': [
        '127.0.0.1',
    ],
}

Usage

To use this module, simply add the IP address to the whitelist via the Django admin interface. Once the IP address is added to the whitelist, during authentication, the user instance will be retrieved based on the user information associated with the IP. If the user instance does not exist in the system, it will be created using the associated username. If a user attempts to access the application from an IP address not listed in the whitelist, they will be prompted that the IP is unauthorized.

Integration with djangorestframework-simplejwt

This module allows seamless integration of django-auth-ipwhitelist with drf-simplejwt, enabling authentication based on IP whitelist directly through the JWT token, in addition to the traditional username/password mode. Here’s how to set it up:
# settings.py
SIMPLE_JWT = {
    ...
    "TOKEN_OBTAIN_SERIALIZER": "django_auth_ipwhitelist.serializers.IPTokenObtainPairSerializer",
}

History

0.1.0 (2024-03-18)

  • First release on PyPI.

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-auth-ipwhitelist-0.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

django_auth_ipwhitelist-0.1.0-py2.py3-none-any.whl (10.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-auth-ipwhitelist-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django-auth-ipwhitelist-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8762bee4fabf61961429c900a510eb043bef074c94e5a04c45ee992c55dde95d
MD5 884267b5f9b5c9b75ba992eb38d76a9a
BLAKE2b-256 3d1107d1d5d46e45040f295ad2816e00a6b3d645fc4ad9e0506ac79e8cc5597a

See more details on using hashes here.

File details

Details for the file django_auth_ipwhitelist-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_auth_ipwhitelist-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4b077e49791964581bfcc9cdd3a3fcda033df3ad6521bcb3cf4fd7ab1d7b13a1
MD5 79096b8bc0089ba484550c35f91b6d6d
BLAKE2b-256 3c8ec2218afe9fa9a4f84f80b2a6ee9a0276c186ddaf159984b24b7a2934d02c

See more details on using hashes here.

Supported by

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