https://github.com/briefmnews/django-ip-access
Access a Django app with authorized IP address
https://github.com/briefmnews/django-ip-access
django ip-access middleware
Last synced: about 1 month ago
JSON representation
Access a Django app with authorized IP address
- Host: GitHub
- URL: https://github.com/briefmnews/django-ip-access
- Owner: briefmnews
- License: gpl-3.0
- Created: 2019-09-04T07:12:31.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-01-14T22:33:47.000Z (5 months ago)
- Last Synced: 2025-04-17T18:59:45.482Z (about 2 months ago)
- Topics: django, ip-access, middleware
- Language: Python
- Size: 64.5 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# django-ip-access
[](https://www.python.org/downloads/release/python-311/)
[](https://docs.djangoproject.com/en/4.2/)
[](https://github.com/briefmnews/django-ip-access/actions/workflows/workflow.yaml)
[](https://codecov.io/gh/briefmnews/django-ip-access)
[](https://github.com/psf/black)
[](https://github.com/PyCQA/bandit)Access a Django app with authorized IP address
## Installation
Install with [pip](https://pip.pypa.io/en/stable/)
```shell script
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:
```python
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:
```python
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.
```shell script
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:
```shell script
make install
```