Skip to main content

RemoteUserBackend

This backend is to be used in conjunction with the RemoteUserMiddleware found in the middleware module of this package, and is used when the server is handling authentication outside of Django.

Attributes

AttributeTypeDescription
create_unknown_userboolean = TrueDetermines whether the authenticate method creates User objects for usernames that don't already exist in the database.

Methods


authenticate()

@classmethod
def authenticate(
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest),
remote_user: str
) - > User | None

The username passed as remote_user is considered trusted. Return the User object with the given username. Create a new User object if create_unknown_user is True.

Parameters

NameTypeDescription
request[HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)The current HTTP request object associated with the authentication attempt.
remote_userstrThe trusted username string provided by the external authentication source.

Returns

TypeDescription
`UserNone`

aauthenticate()

@classmethod
def aauthenticate(
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest),
remote_user: str
) - > User | None

Asynchronous version of authenticate(). The username passed as remote_user is considered trusted.

Parameters

NameTypeDescription
request[HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)The current HTTP request object associated with the authentication attempt.
remote_userstrThe trusted username string provided by the external authentication source.

Returns

TypeDescription
`UserNone`

clean_username()

@classmethod
def clean_username(
username: str
) - > str

Perform any cleaning on the "username" prior to using it to get or create the user object. Return the cleaned username.

Parameters

NameTypeDescription
usernamestrThe raw username string received from the remote authentication system.

Returns

TypeDescription
strThe processed username string ready for database lookup or creation.

configure_user()

@classmethod
def configure_user(
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest),
user: [User](../models/user.md?sid=django_contrib_auth_models_user),
created: bool = True
) - > [User](../models/user.md?sid=django_contrib_auth_models_user)

Configure a user and return the updated user. By default, return the user unmodified.

Parameters

NameTypeDescription
request[HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)The current HTTP request object, useful for accessing session or metadata during configuration.
user[User](../models/user.md?sid=django_contrib_auth_models_user)The User instance that was just retrieved or created by the backend.
createdbool = TrueA flag indicating whether this User instance was newly created in the database.

Returns

TypeDescription
[User](../models/user.md?sid=django_contrib_auth_models_user)The User object after any custom configuration or attribute assignments have been applied.

aconfigure_user()

@classmethod
def aconfigure_user(
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest),
user: [User](../models/user.md?sid=django_contrib_auth_models_user),
created: bool = True
) - > [User](../models/user.md?sid=django_contrib_auth_models_user)

Asynchronous version of configure_user(). Configures a user and returns the updated user.

Parameters

NameTypeDescription
request[HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest)The current HTTP request object, useful for accessing session or metadata during configuration.
user[User](../models/user.md?sid=django_contrib_auth_models_user)The User instance that was just retrieved or created by the backend.
createdbool = TrueA flag indicating whether this User instance was newly created in the database.

Returns

TypeDescription
[User](../models/user.md?sid=django_contrib_auth_models_user)The User object after any custom configuration or attribute assignments have been applied.