Coverage for src/lexigram/auth/protocols.py: 0%

9 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-25 12:26 +0800

1from __future__ import annotations 

2 

3from typing import TYPE_CHECKING, Protocol, runtime_checkable 

4 

5if TYPE_CHECKING: 

6 from lexigram.contracts.auth.models import UserIdentityProtocol 

7 from lexigram.contracts.core.types import TokenPayload 

8 

9 

10@runtime_checkable 

11class TokenValidatorProtocol(Protocol): 

12 """Validates and decodes authentication tokens.""" 

13 

14 async def validate(self, token: str) -> TokenPayload | None: 

15 """Validate a token and return its payload, or None if invalid.""" 

16 ... 

17 

18 async def revoke(self, token: str) -> bool: 

19 """Revoke a token, preventing future validation.""" 

20 ... 

21 

22 

23@runtime_checkable 

24class IdentityResolverProtocol(Protocol): 

25 """Resolves a token payload to a concrete user identity.""" 

26 

27 async def resolve(self, payload: TokenPayload) -> UserIdentityProtocol | None: 

28 """Resolve token payload to user identity.""" 

29 ...