Skip to content

Commit 914cde1

Browse files
joonashaksarahboyce
authored andcommitted
[5.1.x] Fixed #36200 -- Clarified MIDDLEWARE setting updates when using a custom RemoteUserMiddleware.
Backport of 87c5de3 from main.
1 parent f8b72f8 commit 914cde1

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

docs/howto/auth-remote-user.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,27 @@ regardless of ``AUTHENTICATION_BACKENDS``.
7676

7777
If your authentication mechanism uses a custom HTTP header and not
7878
``REMOTE_USER``, you can subclass ``RemoteUserMiddleware`` and set the
79-
``header`` attribute to the desired ``request.META`` key. For example::
79+
``header`` attribute to the desired ``request.META`` key. For example:
80+
81+
.. code-block:: python
82+
:caption: ``mysite/middleware.py``
8083

8184
from django.contrib.auth.middleware import RemoteUserMiddleware
8285

8386

84-
class CustomHeaderMiddleware(RemoteUserMiddleware):
87+
class CustomHeaderRemoteUserMiddleware(RemoteUserMiddleware):
8588
header = "HTTP_AUTHUSER"
8689

90+
This custom middleware is then used in the :setting:`MIDDLEWARE` setting
91+
instead of :class:`django.contrib.auth.middleware.RemoteUserMiddleware`::
92+
93+
MIDDLEWARE = [
94+
"...",
95+
"django.contrib.auth.middleware.AuthenticationMiddleware",
96+
"mysite.middleware.CustomHeaderRemoteUserMiddleware",
97+
"...",
98+
]
99+
87100
.. warning::
88101

89102
Be very careful if using a ``RemoteUserMiddleware`` subclass with a custom

0 commit comments

Comments
 (0)