File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -76,14 +76,27 @@ regardless of ``AUTHENTICATION_BACKENDS``.
76
76
77
77
If your authentication mechanism uses a custom HTTP header and not
78
78
``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``
80
83
81
84
from django.contrib.auth.middleware import RemoteUserMiddleware
82
85
83
86
84
- class CustomHeaderMiddleware (RemoteUserMiddleware):
87
+ class CustomHeaderRemoteUserMiddleware (RemoteUserMiddleware):
85
88
header = "HTTP_AUTHUSER"
86
89
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
+
87
100
.. warning::
88
101
89
102
Be very careful if using a ``RemoteUserMiddleware`` subclass with a custom
You can’t perform that action at this time.
0 commit comments