domain.protocols.refresh_token_service_protocol¶
src.domain.protocols.refresh_token_service_protocol
¶
RefreshTokenServiceProtocol - Domain protocol for refresh token operations.
This protocol defines the interface for refresh token generation and verification. Infrastructure provides the concrete implementation (RefreshTokenService).
Following hexagonal architecture: - Domain defines what it needs (protocol/port) - Infrastructure provides implementation (adapter) - Application layer uses protocol, not concrete implementation
Classes¶
RefreshTokenServiceProtocol
¶
Bases: Protocol
Protocol for refresh token generation and verification.
Generates opaque refresh tokens for long-lived authentication. Tokens are hashed before database storage for security.
Implementations
- RefreshTokenService: src/infrastructure/security/refresh_token_service.py
Source code in src/domain/protocols/refresh_token_service_protocol.py
Functions¶
generate_token
¶
Generate refresh token and its hash.
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
Tuple of (token, token_hash): - token: Plain token to return to user (urlsafe base64) - token_hash: Bcrypt hash to store in database |
Source code in src/domain/protocols/refresh_token_service_protocol.py
verify_token
¶
Verify token against stored hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
Plain token from user request. |
required |
token_hash
|
str
|
Bcrypt hash from database. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if token matches hash, False otherwise. |
Source code in src/domain/protocols/refresh_token_service_protocol.py
calculate_expiration
¶
Calculate expiration timestamp for new token.
Returns:
| Type | Description |
|---|---|
datetime
|
Expiration datetime (UTC) based on configured expiration_days. |