mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-14 18:58:10 +08:00
Add more docstrings
This commit is contained in:
@ -7,6 +7,8 @@ from fastapi_users.models import BaseUserDB
|
||||
|
||||
|
||||
class BaseAuthentication:
|
||||
"""Base adapter for generating and decoding authentication tokens."""
|
||||
|
||||
async def get_login_response(self, user: BaseUserDB, response: Response):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -21,6 +21,12 @@ def generate_jwt(data: dict, lifetime_seconds: int, secret: str, algorithm: str)
|
||||
|
||||
|
||||
class JWTAuthentication(BaseAuthentication):
|
||||
"""
|
||||
Authentication using a JWT.
|
||||
|
||||
:param secret: Secret used to encode the JWT.
|
||||
:param lifetime_seconds: Lifetime duration of the JWT in seconds.
|
||||
"""
|
||||
|
||||
algorithm: str = "HS256"
|
||||
secret: str
|
||||
|
@ -7,6 +7,8 @@ from pydantic.types import EmailStr
|
||||
|
||||
|
||||
class BaseUser(BaseModel):
|
||||
"""Base User model."""
|
||||
|
||||
id: Optional[str] = None
|
||||
email: Optional[EmailStr] = None
|
||||
is_active: Optional[bool] = True
|
||||
@ -31,6 +33,8 @@ class BaseUserDB(BaseUser):
|
||||
|
||||
|
||||
class Models:
|
||||
"""Generate models inheriting from the custom User model."""
|
||||
|
||||
def __init__(self, user_model: Type[BaseUser]):
|
||||
class UserCreate(user_model, BaseUserCreate): # type: ignore
|
||||
pass
|
||||
|
@ -14,6 +14,7 @@ from fastapi_users.password import get_password_hash
|
||||
def get_user_router(
|
||||
user_db: BaseUserDatabase, user_model: Type[BaseUser], auth: BaseAuthentication
|
||||
) -> APIRouter:
|
||||
"""Generate a router with the authentication routes."""
|
||||
router = APIRouter()
|
||||
models = Models(user_model)
|
||||
|
||||
|
Reference in New Issue
Block a user