Package: django-perimeter
# Django PerimeterPerimeter is a Django app that provides middleware that allows you to'secure the perimeter' of your django site outside of any existing authprocess that you have.## Compatibility**This package now requires Python 3.8+ and Django 3.2+.**For previous versions please refer to the relevant branch.## Why?Most django sites have some kind of user registration and security model -a login process, decorators to secure certain URLs, user accounts -everything that comes with `django.contrib.auth` and associated apps.Sometimes, however, you want to simply secure the entire site to preventprying eyes - the classic example being before a site goes live. Youwant to erect a secure perimeter fence around the entire thing. If youhave control over your front-end web server (e.g. Apache, Nginx) thenthis can be used to do this using their in-built access controlfeatures. However, if you are running your app on a hosting platform youmay not have admin access to these parts. Even if you do have controlover your webserver, you may not want to be re-configuring it every timeyou want to grant someone access.That's when you need Perimeter.Perimeter provides simple tokenised access control over your entireDjango site (everything, including the admin site and login pages).## How does it work?Once you have installed and enabled Perimeter, everyone requiring accesswill need an authorisation token (not authentication - there is nothinginherent in Perimeter to prevent people swapping / sharing tokens - thatis an accepted use case).Perimeter runs as middleware that will inspect the user's `session`for a token. If they have a valid token, then they continue to use thesite uninterrupted. If they do not have a token, or the token is invalid(expired or set to inactive), then they are redirected to the Perimeter'Gateway', where they must enter a valid token, along with their nameand email (for auditing purposes - this is stored in the database).To create a new token you need to head to the admin site, and create anew token under the Perimeter app. If you have `PERIMETER_ENABLED` setto True already you won't be able to access the admin site (as Perimetercovers everything except for the perimeter 'gateway' form), and so thereis a management command (`create_access_token`) that you can use tocreate your first token. (This is analagous to the Django setup processwhere it prompts you to create a superuser.)Setup-----1. Add `"perimeter"` to your installed apps.2. Add `"perimeter.middleware.PerimeterAccessMiddleware"` to the list of MIDDLEWARE_CLASSES3. Add the perimeter urls, including the `"perimeter"` namespace.4. Add `PERIMETER_ENABLED = True` to your settings file. This setting can be used to enable or disable Perimeter in different environments.Settings:.. code:: pythonPERIMETER_ENABLED = TrueINSTALLED_APPS = (..."perimeter",...)# Perimeter's middleware must be after SessionMiddleware as it relies on# request.sessionMIDDLEWARE_CLASSES = [..."django.contrib.sessions.middleware.SessionMiddleware","perimeter.middleware.PerimeterAccessMiddleware",...]Site urls:.. code:: python# in site urlsurlpatterns = [...# NB you must include the namespace, as it is referenced in the apppath("perimeter/", include("perimeter.urls", namespace="perimeter")),...]## TestsThe app has a suite of tests, and a ``tox.ini`` file configured to runthem when using ``tox`` (recommended).