Hide your Django site behind basic authentication mechanism with IP
Project description
whitelisting support.
Home-page: https://github.com/tm-kn/django-basic-auth-ip-whitelist
Author: Tomasz Knapik
Author-email: tmkn@tmkn.uk
License: BSD 2-Clause License
Description: django-basic-auth-ip-whitelist
==============================
This simple package ships middleware that lets you to set basic auth and
IP whitelisting via settings.
Use case
--------
This package has been created in mind for staging and demo sites that
need to be completely hidden from the Internet behind a password or IP
range.
Requirements
------------
- Django 1.11 or 2.0
- Python 3.4, 3.5, 3.6
Installation
------------
The package is on
`PyPI <https://pypi-hypernode.com/project/django-basic-auth-ip-whitelist/>`__.
.. code:: bash
pip install django-basic-auth-ip-whitelist
Configuration
-------------
In your Django settings you can configure the following settings.
``BASIC_AUTH_LOGIN`` and ``BASIC_AUTH_PASSWORD``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Credentials that you want to use with your basic authentication.
``BASIC_AUTH_WHITELISTED_IP_NETWORKS``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set a list of network ranges (strings) compatible with Python’s
`ipaddress.ip_network <https://docs.python.org/3.6/library/ipaddress.html#ipaddress.ip_network>`__
that you want to be able to access the website without authentication
from. It must be either a string with networks separated by comma or
Python iterable.
Example settings
~~~~~~~~~~~~~~~~
.. code:: python
MIDDLEWARE += [
'baipw.middleware.BasicAuthIPWhitelistMiddleware'
]
BASIC_AUTH_LOGIN = 'somelogin'
BASIC_AUTH_PASSWORD = 'greatpassword'
BASIC_AUTH_WHITELISTED_IP_NETWORKS = [
'192.168.0.0/28',
'2001:db00::0/24',
]
Advanced customisation
----------------------
Getting IP
~~~~~~~~~~
If you want to have a custom behaviour when getting IP, you can create a
custom function that takes request as a parameter and specify path to it
in the ``BASIC_AUTH_GET_CLIENT_IP_FUNCTION`` settings, e.g.
.. code:: python
BASIC_AUTH_GET_CLIENT_IP_FUNCTION = 'utils.ip.get_client_ip'
Keywords: django,basic,authentication,auth,ip,whitelist,whitelisting,http
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.11
Classifier: Framework :: Django :: 2.0
Home-page: https://github.com/tm-kn/django-basic-auth-ip-whitelist
Author: Tomasz Knapik
Author-email: tmkn@tmkn.uk
License: BSD 2-Clause License
Description: django-basic-auth-ip-whitelist
==============================
This simple package ships middleware that lets you to set basic auth and
IP whitelisting via settings.
Use case
--------
This package has been created in mind for staging and demo sites that
need to be completely hidden from the Internet behind a password or IP
range.
Requirements
------------
- Django 1.11 or 2.0
- Python 3.4, 3.5, 3.6
Installation
------------
The package is on
`PyPI <https://pypi-hypernode.com/project/django-basic-auth-ip-whitelist/>`__.
.. code:: bash
pip install django-basic-auth-ip-whitelist
Configuration
-------------
In your Django settings you can configure the following settings.
``BASIC_AUTH_LOGIN`` and ``BASIC_AUTH_PASSWORD``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Credentials that you want to use with your basic authentication.
``BASIC_AUTH_WHITELISTED_IP_NETWORKS``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set a list of network ranges (strings) compatible with Python’s
`ipaddress.ip_network <https://docs.python.org/3.6/library/ipaddress.html#ipaddress.ip_network>`__
that you want to be able to access the website without authentication
from. It must be either a string with networks separated by comma or
Python iterable.
Example settings
~~~~~~~~~~~~~~~~
.. code:: python
MIDDLEWARE += [
'baipw.middleware.BasicAuthIPWhitelistMiddleware'
]
BASIC_AUTH_LOGIN = 'somelogin'
BASIC_AUTH_PASSWORD = 'greatpassword'
BASIC_AUTH_WHITELISTED_IP_NETWORKS = [
'192.168.0.0/28',
'2001:db00::0/24',
]
Advanced customisation
----------------------
Getting IP
~~~~~~~~~~
If you want to have a custom behaviour when getting IP, you can create a
custom function that takes request as a parameter and specify path to it
in the ``BASIC_AUTH_GET_CLIENT_IP_FUNCTION`` settings, e.g.
.. code:: python
BASIC_AUTH_GET_CLIENT_IP_FUNCTION = 'utils.ip.get_client_ip'
Keywords: django,basic,authentication,auth,ip,whitelist,whitelisting,http
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.11
Classifier: Framework :: Django :: 2.0
Project details
Release history Release notifications | RSS feed
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
Close
Hashes for django-basic-auth-ip-whitelist-0.1.post2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c6e4e2aa24d8306e7b6bab9524d3c2b62b9896032cb465837818edc72577e1b |
|
MD5 | 761599141e88f6d22eacf931dc361dbf |
|
BLAKE2b-256 | 09da597f38cb697f7cbbbb5c77884b699d38d0a0aedff27de02b41e98bbf9207 |
Close
Hashes for django_basic_auth_ip_whitelist-0.1.post2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3a7a434baa4c5be614f860c8665441ace020ce596d7a45093722fe341c7b434 |
|
MD5 | e5a3ead58d4921b4ddc74c45c53b301d |
|
BLAKE2b-256 | 636e100263a2e4f8e4352404b88220e2f3a4da6bcb0e32545869606161ccd1d0 |