Skip to main content

Access a Django app with authorized IP address

Project description

django-ip-access

Python 3.11 Django 4.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.0.tar.gz (20.3 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.0-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_ip_access-3.0.0.tar.gz
  • Upload date:
  • Size: 20.3 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.0.tar.gz
Algorithm Hash digest
SHA256 24d9f9fdf98a756c86bf1f117bf8a924181d9f360809ac3bbcd78a18c2c568fb
MD5 9cc20574021742c7e69884a8591e9990
BLAKE2b-256 7a15e963dd7d9b0d0f967d453fb78c2240baa85b6a74f66ba1922101b68422b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_ip_access-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d589b2db8c3280d25d39fabffb2feab29bb5998238980dcbfb8d7744b189cfc3
MD5 43dbdee600e7e2c8ca262d45cca8b77e
BLAKE2b-256 13e1091917b9650323ed889e914fae2e94955030a80d956984fff4e0c48de0f8

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