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:
|
class BaseAuthentication:
|
||||||
|
"""Base adapter for generating and decoding authentication tokens."""
|
||||||
|
|
||||||
async def get_login_response(self, user: BaseUserDB, response: Response):
|
async def get_login_response(self, user: BaseUserDB, response: Response):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@ -21,6 +21,12 @@ def generate_jwt(data: dict, lifetime_seconds: int, secret: str, algorithm: str)
|
|||||||
|
|
||||||
|
|
||||||
class JWTAuthentication(BaseAuthentication):
|
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"
|
algorithm: str = "HS256"
|
||||||
secret: str
|
secret: str
|
||||||
|
@ -7,6 +7,8 @@ from pydantic.types import EmailStr
|
|||||||
|
|
||||||
|
|
||||||
class BaseUser(BaseModel):
|
class BaseUser(BaseModel):
|
||||||
|
"""Base User model."""
|
||||||
|
|
||||||
id: Optional[str] = None
|
id: Optional[str] = None
|
||||||
email: Optional[EmailStr] = None
|
email: Optional[EmailStr] = None
|
||||||
is_active: Optional[bool] = True
|
is_active: Optional[bool] = True
|
||||||
@ -31,6 +33,8 @@ class BaseUserDB(BaseUser):
|
|||||||
|
|
||||||
|
|
||||||
class Models:
|
class Models:
|
||||||
|
"""Generate models inheriting from the custom User model."""
|
||||||
|
|
||||||
def __init__(self, user_model: Type[BaseUser]):
|
def __init__(self, user_model: Type[BaseUser]):
|
||||||
class UserCreate(user_model, BaseUserCreate): # type: ignore
|
class UserCreate(user_model, BaseUserCreate): # type: ignore
|
||||||
pass
|
pass
|
||||||
|
@ -14,6 +14,7 @@ from fastapi_users.password import get_password_hash
|
|||||||
def get_user_router(
|
def get_user_router(
|
||||||
user_db: BaseUserDatabase, user_model: Type[BaseUser], auth: BaseAuthentication
|
user_db: BaseUserDatabase, user_model: Type[BaseUser], auth: BaseAuthentication
|
||||||
) -> APIRouter:
|
) -> APIRouter:
|
||||||
|
"""Generate a router with the authentication routes."""
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
models = Models(user_model)
|
models = Models(user_model)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user