Skip to main content

Access a Django app with authorized IP address

Project description

django-ip-access

Python 3.11 Django 5.2 Python CI codecov Code style: black security: bandit

Access a Django app with authorized IP address

Installation

Install with pip

pip install django-ip-access

Setup

In order to make django-ip-access works, you'll need to follow the steps below.

Settings

First you need to add the following to your setings:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',

    'django_ip_access',
    ...
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    
    'django_ip_access.middleware.IpAccessMiddleware',
    ...
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    
    'django_ip_access.backends.IpAccessBackend',
    ...
)

The settings with their default values:

IP_ACCESS_URLS_WHITELIST = [] # list of path or absolute urls where the IP authentication will take place. I.e. ["/", "https://www.example.com/hello/"]

Migrations

Next, you need to run the migrations in order to update your database schema.

python manage.py migrate

How to use ?

Once you are all set up, when a request to your app is made, the IpAccessMiddleware checks for if the IP address of the request exists in the admin panel and if the user associated to the IP address is active.

Tests

Testing is managed by pytest. required packages for testing can be installed with:

make install

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_ip_access-3.0.2.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

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

django_ip_access-3.0.2-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file django_ip_access-3.0.2.tar.gz.

File metadata

  • Download URL: django_ip_access-3.0.2.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for django_ip_access-3.0.2.tar.gz
Algorithm Hash digest
SHA256 2d1b08b5b6b21bb24a7b9639f9ed7c1c7a3c64a894cfc78175bc86e590d888ac
MD5 81fc802e3ad027924e0687423f1a9cda
BLAKE2b-256 6bd6ddf82d88aae00fe79e104a6a5f2f5454e1bf0ee0d75c43520b1fb25f6731

See more details on using hashes here.

File details

Details for the file django_ip_access-3.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_ip_access-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 616dddc36d4a33b0c294637795464c3260ec88d073a1aa743d4d7941906748df
MD5 f1d9960f175ee206e77b2f973c793f63
BLAKE2b-256 ae7eb36464e372ab7712aa4c62b8216ea8f5a1920c729b2521406a690e5d9e9e

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