florist.api.auth.token module

Module for handling token and user creation.

class AuthUser(**data)[source]

Bases: BaseModel

Define the User model to be returned by the API.

class Config[source]

Bases: object

Config for the AuthUser model.

allow_population_by_field_name = True
schema_extra = {'example': {'username': 'admin', 'uuid': 'LQv3c1yqBWVHxkd0LHAkCOYz6T'}}
username: str
uuid: str
class Token(**data)[source]

Bases: BaseModel

Define the Token model.

class Config[source]

Bases: object

Config for the Token model.

allow_population_by_field_name = True
schema_extra = {'example': {'access_token': 'LQv3c1yqBWVHxkd0LHAkCOYz6T', 'token_type': 'bearer'}}
access_token: str
token_type: str
create_access_token(data, secret_key, expiration_delta=datetime.timedelta(days=7))[source]

Create an access token.

Parameters:
  • data (dict[str, Any]) – (dict) the data to encode in the token.

  • secret_key (str) – (str) the user’s secret key to encode the token.

  • expiration_delta (timedelta) – (timedelta) the expiration time of the token.

Return type:

str

Returns:

(str) the access token.

decode_access_token(token, secret_key)[source]

Decode an access token.

Parameters:
  • token (str) – (str) the token to decode.

  • secret_key (str) – (str) the user’s secret key to decode the token.

Return type:

dict[str, Any]

Returns:

(dict) the decoded token information.

make_default_client_user()[source]

Make a default client user.

Return type:

UserDAO

Returns:

(User) the default client user.

async make_default_server_user(database)[source]

Make a default server user.

Parameters:

database (AsyncIOMotorDatabase) – (AsyncIOMotorDatabase[Any]) the database to create the user in.

Return type:

User

Returns:

(User) the default server user.

verify_password(password, hashed_password)[source]

Verify if a password matches a hashed password.

Parameters:
  • password (str) – (str) the password to verify.

  • hashed_password (str) – (str) the hashed password to verify against.

Return type:

bool

Returns:

(bool) True if the password matches the hashed password, False otherwise.