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

1"""Overridable interfaces for fastapi-authly.""" 

2 

3from __future__ import annotations 

4 

5from typing import Any, Awaitable, Protocol 

6 

7from .schemas.user import PasswordReset, PasswordResetRequest, UserBase, UserCreate, UserPublic 

8 

9 

10class PasswordHasher(Protocol): 

11 """Interface for password hashing and verification.""" 

12 

13 def hash(self, password: str) -> str: 

14 ... 

15 

16 def verify(self, password: str, hashed: str) -> bool: 

17 ... 

18 

19 

20class TokenService(Protocol): 

21 """Interface for issuing and validating tokens.""" 

22 

23 def create_access_token(self, subject: str) -> str: 

24 ... 

25 

26 def create_refresh_token(self, subject: str) -> str: 

27 ... 

28 

29 def decode_token(self, token: str, verify_type: str | None = None) -> dict[str, Any]: 

30 ... 

31 

32 

33class Mailer(Protocol): 

34 """Interface for delivering email notifications.""" 

35 

36 async def send_password_reset(self, request: PasswordResetRequest, token: str) -> Any: 

37 ... 

38 

39 async def send_verification(self, email: str, token: str) -> Any: 

40 ... 

41 

42 

43class UserRepository(Protocol): 

44 """Interface for user persistence operations.""" 

45 

46 async def get_by_name(self, email: str) -> Any: 

47 ... 

48 

49 async def get_by_id(self, user_id: str | int) -> Any: 

50 ... 

51 

52 async def create_user(self, user: UserCreate) -> Any: 

53 ... 

54 

55 async def to_public(self, user: Any) -> UserPublic: 

56 ...