RemoteUserMiddleware
Middleware for utilizing web-server-provided authentication.
Attributes
| Attribute | Type | Description |
|---|---|---|
| sync_capable | boolean = True | Boolean flag indicating that the middleware is capable of handling synchronous requests. |
| async_capable | boolean = True | Boolean flag indicating that the middleware is capable of handling asynchronous requests. |
| header | string = "REMOTE_USER" | Name of request.META key to grab username from. Note that for request headers, normalization to all uppercase and the addition of a "HTTP_" prefix apply. |
| force_logout_if_no_header | boolean = True | Boolean flag that determines whether to remove an existing authenticated remote-user if the specified header is missing from the request. |
Constructor
Signature
def RemoteUserMiddleware(
get_response: callable
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| get_response | callable | The next middleware or view in the chain that will process the request. |
Methods
process_request()
@classmethod
def process_request(
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)
) - > null
Handles synchronous authentication by checking the configured header and logging in the user if a valid remote user is found.
Parameters
| Name | Type | Description |
|---|---|---|
| request | [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The request object containing META headers and the session to be updated. |
Returns
| Type | Description |
|---|---|
null | Returns None; modifies the request object in-place to include the authenticated user. |
aprocess_request()
@classmethod
def aprocess_request(
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)
) - > null
Handles asynchronous authentication by checking the configured header and performing non-blocking login operations for the remote user.
Parameters
| Name | Type | Description |
|---|---|---|
| request | [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The request object containing META headers and the asynchronous session. |
Returns
| Type | Description |
|---|---|
null | Returns None; modifies the request object in-place via asynchronous authentication methods. |
clean_username()
@classmethod
def clean_username(
username: string,
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)
) - > string
Allow the backend to clean the username, if the backend defines a clean_username method.
Parameters
| Name | Type | Description |
|---|---|---|
| username | string | The raw username string extracted from the request headers. |
| request | [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The request object used to retrieve the current authentication backend from the session. |
Returns
| Type | Description |
|---|---|
string | The cleaned username string as processed by the authentication backend. |
aclean_username()
@classmethod
def aclean_username(
username: string,
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)
) - > string
See clean_username.
Parameters
| Name | Type | Description |
|---|---|---|
| username | string | The raw username string extracted from the request headers. |
| request | [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The request object used to retrieve the current authentication backend from the async session. |
Returns
| Type | Description |
|---|---|
string | The cleaned username string as processed by the authentication backend asynchronously. |
get_username()
@classmethod
def get_username(
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)
) - > string
Retrieves the username from the request's META dictionary using the configured header key.
Parameters
| Name | Type | Description |
|---|---|---|
| request | [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The request object containing the environment variables and headers. |
Returns
| Type | Description |
|---|---|
string | The raw username value found in the request metadata. |