Access a Django app with authorized IP address
Project description
django-ip-access
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 optional settings with their default values:
IP_ACCESS_CACHE_KEY_PREFIX = "ip_auth_" # the cache key will be ip_auth_{ip}
IP_ACCESS_CACHE_TTL = 60 * 5 # in seconds. 5 minutes in this example
Migrations
Next, you need to run the migrations in order to update your database schema.
python manage.py migrate
Cache
Beware that django-ip-access relies on Django's cache framework
to avoid trying to authenticate unauthenticated users on each request.
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.
Future work
- Allow the middleware to only runs for specific routes. This would reduces unnecessary overhead for requests that don't require IP-based authentication.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_ip_access-2.3.0.tar.gz.
File metadata
- Download URL: django_ip_access-2.3.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20d6dd22044391db48094255fa5cd230c9fc72e7e8cd2c718789de851cb15c21
|
|
| MD5 |
0780bb5cb10f2619482ec29f74f59da3
|
|
| BLAKE2b-256 |
1d19b95291f4cf8f2d2c843d5bb9fe06172ebfeabf71a2f4f474ffc726c857ad
|
File details
Details for the file django_ip_access-2.3.0-py3-none-any.whl.
File metadata
- Download URL: django_ip_access-2.3.0-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99a943cff2bca9267f2301f42e2f0dce2ba21964d1d2612193c6ef61bec87c48
|
|
| MD5 |
98222fa8b644cf3a9fb4286400d2eae4
|
|
| BLAKE2b-256 |
1a0027332e33e2b3bdf87f3aadb6c42ee6a05a035404fe99e620e4874a52214e
|