mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-10-29 08:27:43 +08:00
Drop Python 3.9 support
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from typing import Generic, Optional, Protocol
|
||||
from typing import Generic, Protocol
|
||||
|
||||
from fastapi_users import models
|
||||
from fastapi_users.manager import BaseUserManager
|
||||
@ -10,8 +10,8 @@ class StrategyDestroyNotSupportedError(Exception):
|
||||
|
||||
class Strategy(Protocol, Generic[models.UP, models.ID]):
|
||||
async def read_token(
|
||||
self, token: Optional[str], user_manager: BaseUserManager[models.UP, models.ID]
|
||||
) -> Optional[models.UP]: ... # pragma: no cover
|
||||
self, token: str | None, user_manager: BaseUserManager[models.UP, models.ID]
|
||||
) -> models.UP | None: ... # pragma: no cover
|
||||
|
||||
async def write_token(self, user: models.UP) -> str: ... # pragma: no cover
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Generic, Optional, Protocol
|
||||
from typing import Any, Generic, Protocol
|
||||
|
||||
from fastapi_users.authentication.strategy.db.models import AP
|
||||
|
||||
@ -8,8 +8,8 @@ class AccessTokenDatabase(Protocol, Generic[AP]):
|
||||
"""Protocol for retrieving, creating and updating access tokens from a database."""
|
||||
|
||||
async def get_by_token(
|
||||
self, token: str, max_age: Optional[datetime] = None
|
||||
) -> Optional[AP]:
|
||||
self, token: str, max_age: datetime | None = None
|
||||
) -> AP | None:
|
||||
"""Get a single access token by token."""
|
||||
... # pragma: no cover
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import secrets
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Any, Generic, Optional
|
||||
from typing import Any, Generic
|
||||
|
||||
from fastapi_users import exceptions, models
|
||||
from fastapi_users.authentication.strategy.base import Strategy
|
||||
@ -13,14 +13,14 @@ class DatabaseStrategy(
|
||||
Strategy[models.UP, models.ID], Generic[models.UP, models.ID, AP]
|
||||
):
|
||||
def __init__(
|
||||
self, database: AccessTokenDatabase[AP], lifetime_seconds: Optional[int] = None
|
||||
self, database: AccessTokenDatabase[AP], lifetime_seconds: int | None = None
|
||||
):
|
||||
self.database = database
|
||||
self.lifetime_seconds = lifetime_seconds
|
||||
|
||||
async def read_token(
|
||||
self, token: Optional[str], user_manager: BaseUserManager[models.UP, models.ID]
|
||||
) -> Optional[models.UP]:
|
||||
self, token: str | None, user_manager: BaseUserManager[models.UP, models.ID]
|
||||
) -> models.UP | None:
|
||||
if token is None:
|
||||
return None
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from typing import Generic, Optional
|
||||
from typing import Generic
|
||||
|
||||
import jwt
|
||||
|
||||
@ -21,10 +21,10 @@ class JWTStrategy(Strategy[models.UP, models.ID], Generic[models.UP, models.ID])
|
||||
def __init__(
|
||||
self,
|
||||
secret: SecretType,
|
||||
lifetime_seconds: Optional[int],
|
||||
lifetime_seconds: int | None,
|
||||
token_audience: list[str] = ["fastapi-users:auth"],
|
||||
algorithm: str = "HS256",
|
||||
public_key: Optional[SecretType] = None,
|
||||
public_key: SecretType | None = None,
|
||||
):
|
||||
self.secret = secret
|
||||
self.lifetime_seconds = lifetime_seconds
|
||||
@ -41,8 +41,8 @@ class JWTStrategy(Strategy[models.UP, models.ID], Generic[models.UP, models.ID])
|
||||
return self.public_key or self.secret
|
||||
|
||||
async def read_token(
|
||||
self, token: Optional[str], user_manager: BaseUserManager[models.UP, models.ID]
|
||||
) -> Optional[models.UP]:
|
||||
self, token: str | None, user_manager: BaseUserManager[models.UP, models.ID]
|
||||
) -> models.UP | None:
|
||||
if token is None:
|
||||
return None
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import secrets
|
||||
from typing import Generic, Optional
|
||||
from typing import Generic
|
||||
|
||||
import redis.asyncio
|
||||
|
||||
@ -12,7 +12,7 @@ class RedisStrategy(Strategy[models.UP, models.ID], Generic[models.UP, models.ID
|
||||
def __init__(
|
||||
self,
|
||||
redis: redis.asyncio.Redis,
|
||||
lifetime_seconds: Optional[int] = None,
|
||||
lifetime_seconds: int | None = None,
|
||||
*,
|
||||
key_prefix: str = "fastapi_users_token:",
|
||||
):
|
||||
@ -21,8 +21,8 @@ class RedisStrategy(Strategy[models.UP, models.ID], Generic[models.UP, models.ID
|
||||
self.key_prefix = key_prefix
|
||||
|
||||
async def read_token(
|
||||
self, token: Optional[str], user_manager: BaseUserManager[models.UP, models.ID]
|
||||
) -> Optional[models.UP]:
|
||||
self, token: str | None, user_manager: BaseUserManager[models.UP, models.ID]
|
||||
) -> models.UP | None:
|
||||
if token is None:
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user