Move validate_password into UserManager

This commit is contained in:
François Voron
2021-09-14 14:01:57 +02:00
parent fdc8e54253
commit 480a6bc4df
19 changed files with 107 additions and 116 deletions

View File

@@ -43,7 +43,7 @@ class Authenticator:
def __init__(
self,
backends: Sequence[BaseAuthentication],
get_user_manager: UserManagerDependency[models.UD],
get_user_manager: UserManagerDependency[models.UC, models.UD],
):
self.backends = backends
self.get_user_manager = get_user_manager
@@ -108,7 +108,7 @@ class Authenticator:
async def _authenticate(
self,
*args,
user_manager: UserManager[models.UD],
user_manager: UserManager[models.UC, models.UD],
optional: bool = False,
active: bool = False,
verified: bool = False,

View File

@@ -9,7 +9,7 @@ from fastapi_users.manager import UserManager
T = TypeVar("T")
class BaseAuthentication(Generic[T]):
class BaseAuthentication(Generic[T, models.UC, models.UD]):
"""
Base authentication backend.
@@ -28,7 +28,7 @@ class BaseAuthentication(Generic[T]):
self.logout = logout
async def __call__(
self, credentials: Optional[T], user_manager: UserManager[models.UD]
self, credentials: Optional[T], user_manager: UserManager[models.UC, models.UD]
) -> Optional[models.UD]:
raise NotImplementedError()

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, Generic, List, Optional
import jwt
from fastapi import Response
@@ -11,7 +11,9 @@ from fastapi_users.jwt import SecretType, decode_jwt, generate_jwt
from fastapi_users.manager import UserManager, UserNotExists
class CookieAuthentication(BaseAuthentication[str]):
class CookieAuthentication(
Generic[models.UC, models.UD], BaseAuthentication[str, models.UC, models.UD]
):
"""
Authentication backend using a cookie.
@@ -67,7 +69,7 @@ class CookieAuthentication(BaseAuthentication[str]):
async def __call__(
self,
credentials: Optional[str],
user_manager: UserManager[models.UD],
user_manager: UserManager[models.UC, models.UD],
) -> Optional[models.UD]:
if credentials is None:
return None

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, Generic, List, Optional
import jwt
from fastapi import Response
@@ -11,7 +11,9 @@ from fastapi_users.jwt import SecretType, decode_jwt, generate_jwt
from fastapi_users.manager import UserManager, UserNotExists
class JWTAuthentication(BaseAuthentication[str]):
class JWTAuthentication(
Generic[models.UC, models.UD], BaseAuthentication[str, models.UC, models.UD]
):
"""
Authentication backend using a JWT in a Bearer header.
@@ -44,7 +46,7 @@ class JWTAuthentication(BaseAuthentication[str]):
async def __call__(
self,
credentials: Optional[str],
user_manager: UserManager[models.UD],
user_manager: UserManager[models.UC, models.UD],
) -> Optional[models.UD]:
if credentials is None:
return None