application.commands.token_commands¶
src.application.commands.token_commands
¶
Token generation commands (CQRS write operations).
Commands represent user intent to generate authentication tokens. All commands are immutable (frozen=True) and use keyword-only arguments (kw_only=True).
Pattern: - Commands are data containers (no logic) - Handlers execute business logic - Commands don't return values (handlers return Result types)
Classes¶
GenerateAuthTokens
dataclass
¶
Generate JWT access token and opaque refresh token.
Single responsibility: Token generation and persistence only. Called after authentication and session creation.
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
UUID
|
User's unique identifier. |
email |
str
|
User's email address (included in JWT payload). |
roles |
list[str]
|
User's roles for authorization (included in JWT payload). |
session_id |
UUID
|
Session identifier (links refresh token to session). |
Example
command = GenerateAuthTokens( ... user_id=UUID("123e4567-e89b-12d3-a456-426614174000"), ... email="user@example.com", ... roles=["user"], ... session_id=UUID("abc123..."), ... ) result = await handler.handle(command)
Returns Success(AuthTokens) or Failure(error)¶