Skip to main content

Various pieces of useful Auth.

Installation

Install the package:

pip install incuna-auth

Add to your INSTALLED_APPS in settings.py:

INSTALLED_APPS = (
    ...
    incuna_auth,
    ...
)

Add the urls to your ROOT_URLCONF:

urlpatterns = patterns(''
    ...
    url('', include('incuna_auth.urls')),
    ...
)

Add the auth urls in settings.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 syncdb

Warning: 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 using LoginRequiredMiddleware, add LOGIN_EXEMPT_URLS in settings.py:

LOGIN_EXEMPT_URLS = [
    r'^about/',
]

Backend

TODO: Add a run down of the Backend.

Middleware

incuna_auth includes 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, add incuna_auth.middleware.[MiddlewareClassName] to MIDDLEWARE_CLASSES in 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 the LOGIN_PROTECTED_URLS and LOGIN_EXEMPT_URLS Django settings. If those settings do not exist, the middleware protects every URL apart from settings.LOGIN_URL and settings.LOGOUT_URL; otherwise, it will apply to every URL in LOGIN_PROTECTED_URLS apart from those in LOGIN_EXEMPT_URLS.

  • FeinCMSLoginRequiredMiddleware: Enforces that a user must be authenticated in order to access a FeinCMS resource with an access_state of STATE_AUTH_ONLY.

Since CMS pages have unpredictable URLs, and it’s desirable to equip them with customisable authentication, LoginRequiredMiddleware by 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 use FeinCMSLoginRequiredMiddleware to protect access states other than STATE_AUTH_ONLY, make a subclass of it that overrides its get_protected_states method. You’ll also need to ensure the CUSTOM_STATES attribute of your AccessStateExtensionMixin subclass contains the access states you want to protect.

  • Customising the middleware system

The 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 the incuna_auth.middleware.permission module. BasePermissionMiddleware is the base class, and URLPermissionMiddleware and FeinCMSPermissionMiddleware form the backbone of LoginRequiredMiddleware and FeinCMSLoginRequiredMiddleware respectively, 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 called process_request, which is called by Django for any request that passes through this middleware. The permission module middleware implements this by first checking if the requested resource should be protected via a method named is_resource_protected, then checking if the request should be allowed to access a protected resource using deny_access_condition. If the request should be disallowed, the middleware executes a method called deny_access which 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_request just returns None in order to do nothing. This is standard middleware behaviour.

Release files for incuna-auth 4.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for incuna-auth 4.4.0
File Size Uploaded
incuna-auth-4.4.0.tar.gz 29.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for incuna-auth 4.4.0
File Interpreter ABI Platform
incuna_auth-4.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 91.4 kB

Release files / incuna-auth-4.4.0.tar.gz

Download URL incuna-auth-4.4.0.tar.gz
Size 29.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7c2f37d9c0b6343afc70f0d2febff5ccb746c7ae5c42e8768acb5c482d358296
BLAKE2b-256 checksum
How to use checksums
9b1fae9be8ee561050705dc5fe92362814a8f9a5c9bedcb0a32dc2129a2221f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / incuna_auth-4.4.0-py3-none-any.whl

Download URL incuna_auth-4.4.0-py3-none-any.whl
Size 61.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f99be0ea497c07f5c0048b2a987dbd9410aed6243c4f8118116376df83a133f4
BLAKE2b-256 checksum
How to use checksums
c12232aaf1ecbef168ede4f19009adbdd36ba1b8ffe60b69348a2c043c3983db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

10.0.0

2 release files

9.0.0

2 release files

8.1.1

2 release files

8.1.0

2 release files

8.0.0

2 release files

7.4.0

2 release files

7.3.0

2 release files

7.2.1

2 release files

7.2.0

2 release files

7.1.0

2 release files

7.0.0

2 release files

6.0.0

2 release files

5.0.0

1 release file

This release

4.4.0 This release

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.1.0

1 release file

4.0.0

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.5.0

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.6

2 release files

2.3.5

2 release files

2.3.4

2 release files

2.3.3

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.2

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.0.0

1 release file

0.11

1 release file

0.10.4

1 release file

0.10.3

1 release file

0.10.2

1 release file

0.10.1

1 release file

0.10.0

1 release file

0.9.1

1 release file

0.9

1 release file

0.8.5

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.7.2

2 release files

0.6.4

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page