Skip to main content

RemoteUserMiddleware

Middleware for utilizing web-server-provided authentication.

Attributes

AttributeTypeDescription
sync_capableboolean = TrueBoolean flag indicating that the middleware is capable of handling synchronous requests.
async_capableboolean = TrueBoolean flag indicating that the middleware is capable of handling asynchronous requests.
headerstring = "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_headerboolean = TrueBoolean 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

NameTypeDescription
get_responsecallableThe 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

NameTypeDescription
request[HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)The request object containing META headers and the session to be updated.

Returns

TypeDescription
nullReturns 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

NameTypeDescription
request[HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)The request object containing META headers and the asynchronous session.

Returns

TypeDescription
nullReturns 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

NameTypeDescription
usernamestringThe 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

TypeDescription
stringThe 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

NameTypeDescription
usernamestringThe 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

TypeDescription
stringThe 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

NameTypeDescription
request[HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)The request object containing the environment variables and headers.

Returns

TypeDescription
stringThe raw username value found in the request metadata.