(self, request)
| 174 | return await self.get_response(request) |
| 175 | |
| 176 | async def aprocess_request(self, request): |
| 177 | # AuthenticationMiddleware is required so that request.auser exists. |
| 178 | if not hasattr(request, "auser"): |
| 179 | raise ImproperlyConfigured( |
| 180 | "The Django remote user auth middleware requires the" |
| 181 | " authentication middleware to be installed. Edit your" |
| 182 | " MIDDLEWARE setting to insert" |
| 183 | " 'django.contrib.auth.middleware.AuthenticationMiddleware'" |
| 184 | f" before the {self.__class__.__name__} class." |
| 185 | ) |
| 186 | try: |
| 187 | username = self.get_username(request) |
| 188 | except KeyError: |
| 189 | # If specified header doesn't exist then remove any existing |
| 190 | # authenticated remote-user, or return (leaving request.user set to |
| 191 | # AnonymousUser by the AuthenticationMiddleware). |
| 192 | if self.force_logout_if_no_header: |
| 193 | user = await request.auser() |
| 194 | if user.is_authenticated: |
| 195 | await self._aremove_invalid_user(request) |
| 196 | return |
| 197 | user = await request.auser() |
| 198 | # If the user is already authenticated and that user is the user we are |
| 199 | # getting passed in the headers, then the correct user is already |
| 200 | # persisted in the session and we don't need to continue. |
| 201 | if user.is_authenticated: |
| 202 | if user.get_username() == await self.aclean_username(username, request): |
| 203 | return |
| 204 | else: |
| 205 | # An authenticated user is associated with the request, but |
| 206 | # it does not match the authorized user in the header. |
| 207 | await self._aremove_invalid_user(request) |
| 208 | |
| 209 | # We are seeing this user for the first time in this session, attempt |
| 210 | # to authenticate the user. |
| 211 | user = await auth.aauthenticate(request, remote_user=username) |
| 212 | if user: |
| 213 | # User is valid. Persist the user in the session by logging the |
| 214 | # user in. |
| 215 | await auth.alogin(request, user) |
| 216 | |
| 217 | def clean_username(self, username, request): |
| 218 | """ |
no test coverage detected