Skip to content

User

eternaltwin.users.User

User(identifier: str, username: str, is_administrator: bool | None, created_at: datetime | None, deleted_at: datetime | None, token: Token | None = None)

Represents a user.

is_authenticated property

is_authenticated: bool

Whether the user is authenticated.

start_authorization classmethod

start_authorization(expiration: int = 600, nonce: str = None, using: str = None) -> tuple[str, str]

Start the authorization process, returning a state and an authorization URL.

Parameters:

Name Type Description Default
expiration int

Expiration time in seconds. Default to 600 seconds.

600
nonce str

An optional nonce value used to guarantee the state to be unique. If not provided, a random one will be generated.

None
using str

The name of the connection to use, default to None for the default connection.

None
Return

tuple[str, str] The generated state and the authorization URL.

from_token classmethod

from_token(token: Token, using: str | None = None) -> Self

Retrieve the user associated with the provided token.

afrom_token async classmethod

afrom_token(token: Token, using: str | None = None) -> Self

Retrieve the user associated with the provided token.

from_authorization_code classmethod

from_authorization_code(authorization_code: str, callback_state: str, expected_state: str | None = None, using: str | None = None) -> Self

Retrieve the user associated with the provided authorization code.

Validate the state received from the authorization server.

An expected state can be provided to check if the state received from the authorization server matches the expected one.

Raises:

Type Description
InvalidStateError

If action or authorization server does not match, the JWT is expired, or the received state does not match the expected one (if provided).

afrom_authorization_code async classmethod

afrom_authorization_code(authorization_code: str, callback_state: str, expected_state: str | None = None, using: str | None = None) -> Self

Retrieve the user associated with the provided authorization code.

Validate the state received from the authorization server.

An expected state can be provided to check if the state received from the authorization server matches the expected one.

Raises:

Type Description
InvalidStateError

If action or authorization server does not match, the JWT is expired, or the received state does not match the expected one (if provided).

get classmethod

get(user_id: str, using: str | None = None) -> Self

Retrieve a specific user.

aget async classmethod

aget(user_id: str, using: str | None = None) -> Self

Retrieve a specific user.

search classmethod

search(query: str | None = None, limit: int = 20, offset: int = 0, using: str | None = None) -> list[Self]

Search for users matching the query.

Parameters:

Name Type Description Default
query str | None

An optional query to use against the user's username, default to None.

None
limit int

The maximum number of users to return, default to 20.

20
offset int

The offset to start returning users from, default to 0.

0

asearch async classmethod

asearch(query: str | None = None, limit: int = 20, offset: int = 0, using: str | None = None) -> list[Self]

Search for users matching the query.

Parameters:

Name Type Description Default
query str | None

An optional query to use against the user's username, default to None.

None
limit int

The maximum number of users to return, default to 20.

20
offset int

The offset to start returning users from, default to 0.

0

count classmethod

count(query: str | None = None, using: str | None = None) -> int

Search the number of users matching the query.

If query is not provided, return the total number of users.

acount async classmethod

acount(query: str | None = None, using: str | None = None) -> int

Search the number of users matching the query.

If query is not provided, return the total number of users.

logout

logout() -> None

Logout the user by deleting their token.