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.1.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.1-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_ip_access-3.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 2f2bec077d3b65aa44a1efb9393bedada82fe2a154cdf86c8baeb2a1bec5fb1b
MD5 6f059726c3063ac24e37831fe542f15f
BLAKE2b-256 cdfa092de3e10972528ae6f16bf981d8f110fc28c5ecb12f140e07b09ccde59a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_ip_access-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8148b0c8aa00e331fb30f848997df2feb2cdee524ffcae458af49636a389a63a
MD5 e02ded7a895347a90d8db5fc07e697fa
BLAKE2b-256 e06cef2467eb0f3321bc9f78f421bcb9ab0d3c2caa555187c733b8bce772402e

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