3.2. authentication module¶
- class authentication.AuthenticationMiddleware(app: ASGIApp, exclude: str | list[str] | None = None, exclude_from_auth_key: str = 'exclude_from_auth', exclude_http_methods: Sequence[Method] | None = None, scopes: Scopes | None = None)[source]¶
Bases:
AbstractAuthenticationMiddlewareMiddleware that checks if the user has provided a valid jwt auth key as the ‘Authentication’ HTTP header.
- app¶
- async authenticate_request(connection: ASGIConnection) AuthenticationResult[source]¶
Receive the http connection and return an
AuthenticationResult.- Notes:
This method must be overridden by subclasses.
- Args:
connection: An
ASGIConnectioninstance.- Raises:
NotAuthorizedException | PermissionDeniedException: if authentication fails.
- Returns:
An instance of
AuthenticationResult.
- exclude¶
- exclude_http_methods¶
- exclude_opt_key¶
- scopes¶
- class authentication.ChangePasswordRequest(old_password: str, new_password: str)[source]¶
Bases:
object- new_password: str¶
- old_password: str¶
- class authentication.JwtUser(id: str, name: str, email: str)[source]¶
Bases:
object- email: str¶
- id: str¶
- name: str¶
- class authentication.LoginRequest(name: str, password: str, two_fa_code: str | None = None, webauthn_response: dict[str, Any] | None = None)[source]¶
Bases:
objectParameters sent by the user in order to login.
- name: str¶
- password: str¶
- two_fa_code: str | None = None¶
- webauthn_response: dict[str, Any] | None = None¶
- class authentication.ResetPasswordRequest(new_password: str)[source]¶
Bases:
object- new_password: str¶
- class authentication.TotpConfiguredResponse(is_configured: bool)[source]¶
Bases:
object- is_configured: bool¶
- class authentication.TotpSetupResponse(secret: str, otpauth_uri: str)[source]¶
Bases:
object- otpauth_uri: str¶
- secret: str¶
- class authentication.TwoFaRequiredResponse(user_id: str, totp_supported: bool, webauthn_supported: bool)[source]¶
Bases:
object- totp_supported: bool¶
- user_id: str¶
- webauthn_supported: bool¶
- async authentication.get_user_by_name_or_mail(db_session: AsyncSession, query: str) User | None[source]¶
Get a user by their name (case-insensitive).
This method tries to find a user with the given username first. If there’s none, it falls back to searching a user whose email equals the query.
param query: the username or email to search for return: the user for the given query, or None if no such user exists