Files
François Voron 72aa68c462 Native model and generic ID (#971)
* Use a generic Protocol model for User instead of Pydantic

* Remove UserDB Pydantic schema

* Harmonize schema variable naming to avoid confusions

* Revamp OAuth account model management

* Revamp AccessToken DB strategy to adopt generic model approach

* Make ID a generic instead of forcing UUIDs

* Improve generic typing

* Improve Strategy typing

* Tweak base DB typing

* Don't set Pydantic schemas on FastAPIUsers class: pass it directly on router creation

* Add IntegerIdMixin and export related classes

* Start to revamp doc for V10

* Revamp OAuth documentation

* Fix code highlights

* Write the 9.x.x ➡️ 10.x.x migration doc

* Fix pyproject.toml
2022-05-05 14:51:19 +02:00

52 lines
1.1 KiB
Python

import sys
from typing import Generic, List, Optional, TypeVar
if sys.version_info < (3, 8):
from typing_extensions import Protocol # pragma: no cover
else:
from typing import Protocol # pragma: no cover
ID = TypeVar("ID")
class UserProtocol(Protocol[ID]):
"""User protocol that ORM model should follow."""
id: ID
email: str
hashed_password: str
is_active: bool
is_superuser: bool
is_verified: bool
def __init__(self, *args, **kwargs) -> None:
... # pragma: no cover
class OAuthAccountProtocol(Protocol[ID]):
"""OAuth account protocol that ORM model should follow."""
id: ID
oauth_name: str
access_token: str
expires_at: Optional[int]
refresh_token: Optional[str]
account_id: str
account_email: str
def __init__(self, *args, **kwargs) -> None:
... # pragma: no cover
UP = TypeVar("UP", bound=UserProtocol)
OAP = TypeVar("OAP", bound=OAuthAccountProtocol)
class UserOAuthProtocol(UserProtocol[ID], Generic[ID, OAP]):
"""User protocol including a list of OAuth accounts."""
oauth_accounts: List[OAP]
UOAP = TypeVar("UOAP", bound=UserOAuthProtocol)