reviewboard.accounts.backends.base¶
Base class for authentication backends.
- class BaseAuthBackend[source]¶
Bases:
object
Base class for a Review Board authentication backend.
- name: Optional[StrOrPromise] = None¶
The display name for the authentication backend.
This will be shown in the list of backends in the administration UI.
- Type:
- settings_form: Optional[Type[SiteSettingsForm]] = None¶
The form class used for authentication settings.
This must be a subclass of
SiteSettingsForm
.- Type:
- supports_change_name: bool = False¶
Whether this backend supports changing the user’s full name.
- Type:
- supports_change_email: bool = False¶
Whether this backend supports changing the user’s e-mail address.
- Type:
- supports_change_password: bool = False¶
Whether this backend supports changing the user’s password.
- Type:
- login_instructions: Optional[StrOrPromise] = None¶
Authentication instructions to display above the Login form.
- Type:
- INVALID_USERNAME_CHAR_REGEX: re.Pattern = re.compile('[^\\w.@+-]')¶
A regex for matching invalid characters in usernames.
- Type:
- authenticate(request: Optional[HttpRequest] = None, **credentials) Optional[User] [source]¶
Authenticate a user.
This will authenticate a user identified by the provided credentials. object, or None.
This must be implemented by subclasses.
Changed in version 6.0:
request
is now optional.Changed in version 4.0: The
request
argument is now mandatory as the first positional argument, as per requirements in Django.- Parameters:
request (
django.http.HttpRequest
) – The HTTP request from the caller. This may beNone
.**credentials (
dict
) – The credentials passed to the backend. This will often containusername
andpassword
keys.
- Returns:
The authenticated user, or
None
if the user could not be authenticated for any reason.- Return type:
- get_or_create_user(username: str, request: Optional[HttpRequest] = None) Optional[User] [source]¶
Return an existing user or create one if it doesn’t exist.
This does not authenticate the user.
If the user does not exist in the database, but does in the backend, its information will be stored in the database for later lookup. Subclasses can impose restrictions on this.
This must be implemented by subclasses.
- Parameters:
username (
str
) – The username to fetch or create.request (
django.http.HttpRequest
, optional) – The HTTP request from the client.
- Returns:
The resulting user, or
None
if one could not be found.- Return type:
- get_user(user_id: Union[int, str]) Optional[User] [source]¶
Return an existing user given a numeric user ID.
- Parameters:
- Returns:
The resulting user, or
None
if one could not be found.- Return type:
- update_password(user: User, password: str) None [source]¶
Update a user’s password on the backend.
Authentication backends can override this to update the password on the backend. By default, this is not supported.
Callers should only call this after checking whether
supports_change_password
isTrue
.- Parameters:
user (
django.contrib.auth.models.User
) – The user whose password will be changed.password (
str
) – The new password.
- Raises:
NotImplementedError – The backend does not support changing passwords.
- update_name(user: User) None [source]¶
Update a user’s full name on the backend.
Authentication backends can override this to update the name on the backend based on the
first_name
andlast_name
values inuser
. By default, this will do nothing.Callers should only call this after checking whether
supports_change_name
isTrue
.- Parameters:
user (
django.contrib.auth.models.User
) – The user whose full name will be changed.
- update_email(user: User) None [source]¶
Update a user’s e-mail address on the backend.
Authentication backends can override this to update the e-mail address on the backend based on the
email
value inuser
. NBy default, this will do nothing.Callers should only call this after checking whether
supports_change_email
isTrue
.- Parameters:
user (
django.contrib.auth.models.User
) – The user whose full name will be changed.
- populate_users(query: str, request: Optional[HttpRequest] = None, **kwargs) None [source]¶
Populate users from the backend into the database based on a query.
Authentication backends can override this to add users stored on the backend into the local database, based on a query string representing a full or partial first name, last name, or username. Each result that’s found based on the query should be stored in the database by the backend, generally using the same creation logic as in
get_or_create_user()
.Callers should use this when they need to look up all available users from a backend. After calling this, they should look up the results from the database.
By default, this does nothing.
Changed in version 6.0:
request
is now optional.- Parameters:
query (
str
) – A search query for matching users. This will match the entirety or prefix of a username. It’s expected that the match will be case-insensitive.request (
django.http.HttpRequest
) – The HTTP request from the client.**kwargs (
dict
) – Extra positional arguments, for future use.
- Raises:
reviewboard.accounts.errors.UserQueryError – There was an error processing the query or looking up users. Details will be in the error message.
- build_search_users_query(query: str, request: Optional[HttpRequest] = None, **kwargs) Optional[Q] [source]¶
Build a query for searching users in the database.
This allows backends to construct specialized search queries ( for use in
QuerySet.filter()
when searching for users via the User List Resource.By default, this will return
None
.Changed in version 6.0:
request
is now optional.- Parameters:
query (
str
) – A search query for matching users. This will match the entirety or prefix of a username. It’s expected that the match will be case-insensitive.request (
django.http.HttpRequest
) – The HTTP request from the client.**kwargs (
dict
) – Extra positional arguments, for future use.
- Returns:
The resulting query for the queryset, or
None
to use the query for the next available backend (eventually defaulting to the standard search query).- Return type:
- __annotations__ = {'INVALID_USERNAME_CHAR_REGEX': 're.Pattern', 'backend_id': 'Optional[str]', 'login_instructions': 'Optional[StrOrPromise]', 'name': 'Optional[StrOrPromise]', 'settings_form': 'Optional[Type[SiteSettingsForm]]', 'supports_change_email': 'bool', 'supports_change_name': 'bool', 'supports_change_password': 'bool', 'supports_registration': 'bool'}¶