Coverage for src/lexigram/auth/hooks.py: 100%
23 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 12:26 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 12:26 +0800
1"""Root hook payload surface for lexigram-auth.
3Defines canonical payload dataclasses for auth-lifecycle hook points. Actual
4hook registration and invocation use the framework's string-keyed
5``HookRegistryProtocol`` action/filter APIs.
6"""
8from __future__ import annotations
10from dataclasses import dataclass
12__all__ = [
13 "AuthAuthenticationFailedHook",
14 "AuthTokenIssuedHook",
15 "AuthTokenRefreshedHook",
16 "AuthTokenRevokedHook",
17 "AuthUserAuthenticatedHook",
18]
21@dataclass(frozen=True, kw_only=True)
22class AuthUserAuthenticatedHook:
23 """Payload fired when a user successfully authenticates.
25 Attributes:
26 user_id: Identifier of the authenticated user.
27 method: Authentication method used (e.g. ``"password"``, ``"oauth2"``).
28 """
30 user_id: str
31 method: str
34@dataclass(frozen=True, kw_only=True)
35class AuthAuthenticationFailedHook:
36 """Payload fired when an authentication attempt fails.
38 Attributes:
39 method: Authentication method that was attempted.
40 reason: Short description of why authentication failed.
41 """
43 method: str
44 reason: str
47@dataclass(frozen=True, kw_only=True)
48class AuthTokenIssuedHook:
49 """Payload fired when an access or refresh token is issued.
51 Attributes:
52 user_id: Identifier of the user the token was issued for.
53 token_type: Token kind (e.g. ``"access"``, ``"refresh"``).
54 """
56 user_id: str
57 token_type: str
60@dataclass(frozen=True, kw_only=True)
61class AuthTokenRevokedHook:
62 """Payload fired when a token is explicitly revoked.
64 Attributes:
65 user_id: Identifier of the user whose token was revoked.
66 token_type: Token kind that was revoked.
67 """
69 user_id: str
70 token_type: str
73@dataclass(frozen=True, kw_only=True)
74class AuthTokenRefreshedHook:
75 """Payload fired when an access token is refreshed.
77 Attributes:
78 user_id: Identifier of the user whose token was refreshed.
79 token_type: Token kind that was refreshed.
80 """
82 user_id: str
83 token_type: str