mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-15 11:11:16 +08:00
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from typing import Any, Generic, Optional, TypeVar
|
|
|
|
from fastapi import Response
|
|
from fastapi.security.base import SecurityBase
|
|
|
|
from fastapi_users import models
|
|
from fastapi_users.manager import BaseUserManager
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
class BaseAuthentication(Generic[T, models.UC, models.UD]):
|
|
"""
|
|
Base authentication backend.
|
|
|
|
Every backend should derive from this class.
|
|
|
|
:param name: Name of the backend.
|
|
:param logout: Whether or not this backend has a logout process.
|
|
"""
|
|
|
|
scheme: SecurityBase
|
|
name: str
|
|
logout: bool
|
|
|
|
def __init__(self, name: str = "base", logout: bool = False):
|
|
self.name = name
|
|
self.logout = logout
|
|
|
|
async def __call__(
|
|
self,
|
|
credentials: Optional[T],
|
|
user_manager: BaseUserManager[models.UC, models.UD],
|
|
) -> Optional[models.UD]:
|
|
raise NotImplementedError()
|
|
|
|
async def get_login_response(self, user: models.UD, response: Response) -> Any:
|
|
raise NotImplementedError()
|
|
|
|
async def get_logout_response(self, user: models.UD, response: Response) -> Any:
|
|
raise NotImplementedError()
|