Coverage for src / fastapi_authly / interfaces.py: 62%
29 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-20 11:54 +0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-20 11:54 +0800
1"""Overridable interfaces for fastapi-authly."""
3from __future__ import annotations
5from typing import Any, Awaitable, Protocol
7from .schemas.user import PasswordReset, PasswordResetRequest, UserBase, UserCreate, UserPublic
10class PasswordHasher(Protocol):
11 """Interface for password hashing and verification."""
13 def hash(self, password: str) -> str:
14 ...
16 def verify(self, password: str, hashed: str) -> bool:
17 ...
20class TokenService(Protocol):
21 """Interface for issuing and validating tokens."""
23 def create_access_token(self, subject: str) -> str:
24 ...
26 def create_refresh_token(self, subject: str) -> str:
27 ...
29 def decode_token(self, token: str, verify_type: str | None = None) -> dict[str, Any]:
30 ...
33class Mailer(Protocol):
34 """Interface for delivering email notifications."""
36 async def send_password_reset(self, request: PasswordResetRequest, token: str) -> Any:
37 ...
39 async def send_verification(self, email: str, token: str) -> Any:
40 ...
43class UserRepository(Protocol):
44 """Interface for user persistence operations."""
46 async def get_by_name(self, email: str) -> Any:
47 ...
49 async def get_by_id(self, user_id: str | int) -> Any:
50 ...
52 async def create_user(self, user: UserCreate) -> Any:
53 ...
55 async def to_public(self, user: Any) -> UserPublic:
56 ...