Skip to content

Commit 65fc0d0

Browse files
committed
Ensure request.auth is available to response middleware.
1 parent 7fbf5b0 commit 65fc0d0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

rest_framework/request.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ def user(self, value):
278278
compatibility with django.contrib.auth where the user property is
279279
set in the login and logout functions.
280280
281-
Sets the user on the wrapped original request as well.
281+
Note that we also set the user on Django's underlying `HttpRequest`
282+
instance, ensuring that it is available to any middleware in the stack.
282283
"""
283284
self._user = value
284285
self._request.user = value
@@ -300,6 +301,7 @@ def auth(self, value):
300301
request, such as an authentication token.
301302
"""
302303
self._auth = value
304+
self._request.auth = value
303305

304306
@property
305307
def successful_authenticator(self):
@@ -459,7 +461,7 @@ def _authenticate(self):
459461

460462
if user_auth_tuple is not None:
461463
self._authenticator = authenticator
462-
self.user, self._auth = user_auth_tuple
464+
self.user, self.auth = user_auth_tuple
463465
return
464466

465467
self._not_authenticated()
@@ -479,9 +481,9 @@ def _not_authenticated(self):
479481
self.user = None
480482

481483
if api_settings.UNAUTHENTICATED_TOKEN:
482-
self._auth = api_settings.UNAUTHENTICATED_TOKEN()
484+
self.auth = api_settings.UNAUTHENTICATED_TOKEN()
483485
else:
484-
self._auth = None
486+
self.auth = None
485487

486488
def __getattr__(self, attr):
487489
"""

0 commit comments

Comments
 (0)