Package: incuna-auth
Various pieces of useful Auth.InstallationInstall the package:pip install incuna-authAdd to yourINSTALLED_APPSinsettings.py:INSTALLED_APPS = (
    ...
    incuna_auth,
    ...
)Add the urls to yourROOT_URLCONF:urlpatterns = patterns(''
    ...
    url('', include('incuna_auth.urls')),
    ...
)Add the auth urls insettings.py:from django.core.urlresolvers import reverse_lazy

...

LOGIN_URL = reverse_lazy('login')
LOGOUT_URL = reverse_lazy('logout')Add the tables to the db:python manage.py syncdbWarning: An initial data fixture is included that creates an admin_sso.Assignment to assign any user with an incuna.com email to the Admin user.To allow anonymous access to urls inaccessible by default when usingLoginRequiredMiddleware, addLOGIN_EXEMPT_URLSinsettings.py:LOGIN_EXEMPT_URLS = [
    r'^about/',
]BackendTODO: Add a run down of the Backend.Middlewareincuna_authincludes several useful bits of middleware that can be used to enforce authentication in your project.The middleware is extensible, and compatible with FeinCMS.There are two main middleware classes that can be straightforwardly installed in your project.  To add either of these middlewares, addincuna_auth.middleware.[MiddlewareClassName]toMIDDLEWARE_CLASSESin your project’s settings.LoginRequiredMiddleware: Enforces that a user must be authenticated in order to access any protected URL.This middleware’s coverage can be easily customised with theLOGIN_PROTECTED_URLSandLOGIN_EXEMPT_URLSDjango settings.  If those settings do not exist, the middleware protects every URL apart fromsettings.LOGIN_URLandsettings.LOGOUT_URL; otherwise, it will apply to every URL inLOGIN_PROTECTED_URLSapart from those inLOGIN_EXEMPT_URLS.FeinCMSLoginRequiredMiddleware: Enforces that a user must be authenticated in order to access a FeinCMS resource with anaccess_stateofSTATE_AUTH_ONLY.Since CMS pages have unpredictable URLs, and it’s desirable to equip them with customisable authentication,LoginRequiredMiddlewareby itself is unsuitable for use with FeinCMS.  This middleware is intended for use with an extension that adds a new field,access_state, to a FeinCMS Page or similar item.  We’ve included a mixin,incuna_auth.models.AccessStateExtensionMixin, that makes creating one of these extensions straightforward.To useFeinCMSLoginRequiredMiddlewareto protect access states other thanSTATE_AUTH_ONLY, make a subclass of it that overrides itsget_protected_statesmethod.  You’ll also need to ensure theCUSTOM_STATESattribute of yourAccessStateExtensionMixinsubclass contains the access states you want to protect.Customising the middleware systemThe middleware system is easily extensible, and there’s a small framework of parent classes behind them to make creating your own similar middlewares straightforward, all in theincuna_auth.middleware.permissionmodule.BasePermissionMiddlewareis the base class, andURLPermissionMiddlewareandFeinCMSPermissionMiddlewareform the backbone ofLoginRequiredMiddlewareandFeinCMSLoginRequiredMiddlewarerespectively, together with a mixin that provides an appropriate access-denial condition and error output for enforcing that a user is logged in.Any middleware class has a core method calledprocess_request, which is called by Django for any request that passes through this middleware. Thepermissionmodule middleware implements this by first checking if the requested resource should be protected via a method namedis_resource_protected, then checking if the request should be allowed to access a protected resource usingdeny_access_condition.  If the request should be disallowed, the middleware executes a method calleddeny_accesswhich returns an error response (403 or 302 depending on the nature of the request); if the resource is unprotected or the request is allowed,process_requestjust returnsNonein order to do nothing. This is standard middleware behaviour.Translate urlsBy default the url translations are disabled. To enabled url translations setTRANSLATE_URLS=Truein your protect settings file. Seehttps://docs.djangoproject.com/en/dev/topics/i18n/translation/#url-internationalizationfor more info on translating urls in django.