Skip to main content

Set of middlewares to simplify consumption of external identity information in Web projects set up with Django Web framework.

identity.external.PersistentRemoteUserMiddlewareVar

When non-standard (different than REMOTE_USER) environment variable is used to pass information about externally authenticated user, this middleware can be used to customize the variable name without writing Python code.

For example, when consuming the information from some authentication HTTP proxy, HTTP request header values are passed as HTTP_-prefixed environment variables. If the authenticated user name is in X-Remote-User HTTP request header, it is available in HTTP_X_REMOTE_USER environment variable. Setting variable REMOTE_USER_VAR to HTTP_X_REMOTE_USER, for example with Apache HTTP Server directive

SetEnv REMOTE_USER_VAR HTTP_X_REMOTE_USER

and enabling identity.external.PersistentRemoteUserMiddlewareVar in MIDDLEWARE list after django.contrib.auth.middleware.AuthenticationMiddleware like

MIDDLEWARE = [
        ...
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'identity.external.PersistentRemoteUserMiddlewareVar',
        ...
]

will run django.contrib.auth.middleware.PersistentRemoteUserMiddleware with value from environment variable HTTP_X_REMOTE_USER.

identity.external.RemoteUserAttrMiddleware

When user is externally authenticated, for example via django.contrib.auth.middleware.RemoteUserMiddleware or django.contrib.auth.middleware.PersistentRemoteUserMiddleware, additional user attributes can be provided by the external authentication source.

This middleware will update user’s email address, first and last name, and group membership in groups prefixed with ext: with information coming from environment variables

  • REMOTE_USER_EMAIL

  • REMOTE_USER_FIRSTNAME

  • REMOTE_USER_LASTNAME

  • REMOTE_USER_GROUP_N

  • REMOTE_USER_GROUP_1, REMOTE_USER_GROUP_2, …

  • REMOTE_USER_GROUPS

where the REMOTE_USER prefix of these variables can be changed with the REMOTE_USER_VAR environment variable, just like with identity.external.PersistentRemoteUserMiddlewareVar.

The values are used verbating, as provided by Django. When REMOTE_USER_VALUES_ENCODING environment variable is set to base64url, the values are expected to be in this format and decoded to Unicode.

Users that are in external group admins (and thus get assigned to group ext:admins in Django) will also get the is_staff flag set and thus will be able to log in to the admin application.

The ext: prefixed groups have to be already created in Django database for the user membership to be updated in them.

In the MIDDLEWARE list, this middleware has to be listed after the authenticating middleware, for example

MIDDLEWARE = [
    ...
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.PersistentRemoteUserMiddleware',
    'identity.external.RemoteUserAttrMiddleware',
    ...
]

See also

Release files for django-identity-external 0.8.1

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

Source distribution (sdist)

Source distribution for django-identity-external 0.8.1
File Size Uploaded
django_identity_external-0.8.1.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-identity-external 0.8.1
File Interpreter ABI Platform
django_identity_external-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 kB

Release files / django_identity_external-0.8.1.tar.gz

Download URL django_identity_external-0.8.1.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c93ec91dd56cee3d1fdd40e306d112fcd5f29b9321a59bb95c931baf0113cca3
BLAKE2b-256 checksum
How to use checksums
d87601528d9e4f6eb9801247903e8db9d1f7ba88f70c7fa4b44180ec03b0e138
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / django_identity_external-0.8.1-py3-none-any.whl

Download URL django_identity_external-0.8.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e016d63499a950da532f2d7928e1f49d95fabe386e816b2b91593edee47ef137
BLAKE2b-256 checksum
How to use checksums
67e961076c70941bc52accf3aed06bafb9b91b62a96770570fdcf46ec6febdce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.8.1 This release

2 release files

0.7.1

1 release file

0.6.1

1 release file

0.5.3

1 release file

0.5

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