Skip to main content
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

Copyright (c) 2018, Tomasz Knapik
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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.org/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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-basic-auth-ip-whitelist-0.1.post1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file django-basic-auth-ip-whitelist-0.1.post1.tar.gz.

File metadata

File hashes

Hashes for django-basic-auth-ip-whitelist-0.1.post1.tar.gz
Algorithm Hash digest
SHA256 69a00eac262badf884b66afc96ca1d9f382138b874283b10434d373533c742be
MD5 bed95d6e9336d00fd0f21fd00ca21a61
BLAKE2b-256 ec661a4a3fe9e403a079861dc12176c50d822d7d2fe1bb1e6ff6b6731ad5905b

See more details on using hashes here.

File details

Details for the file django_basic_auth_ip_whitelist-0.1.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_basic_auth_ip_whitelist-0.1.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 36fca5ea48c4eb573a63f8cda6478098b7cdd2b1cf03712d28361e7c38a2fefc
MD5 422524b33fc2c8dff25ee96b4be7f64f
BLAKE2b-256 a39a8c503bda4e2bfd69f5bbf889ef43b8268ea1a5402d8e7be8945b60424fc2

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