Complete OAuth-based authentication with JWT session management:
Core Services:
- JWT service for access/refresh token creation and verification
- Token store with Redis-backed refresh token revocation
- User service for CRUD operations and OAuth-based creation
- Google and Discord OAuth services with full flow support
API Endpoints:
- GET /api/auth/{google,discord} - Start OAuth flows
- GET /api/auth/{google,discord}/callback - Handle OAuth callbacks
- POST /api/auth/refresh - Exchange refresh token for new access token
- POST /api/auth/logout - Revoke single refresh token
- POST /api/auth/logout-all - Revoke all user sessions
- GET/PATCH /api/users/me - User profile management
- GET /api/users/me/linked-accounts - List OAuth providers
- GET /api/users/me/sessions - Count active sessions
Infrastructure:
- Pydantic schemas for auth/user request/response models
- FastAPI dependencies (get_current_user, get_current_premium_user)
- OAuthLinkedAccount model for multi-provider support
- Alembic migration for oauth_linked_accounts table
Dependencies added: email-validator, fakeredis (dev), respx (dev)
84 new tests, 1058 total passing
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
"""Database models for Mantimon TCG.
|
|
|
|
This module exports all SQLAlchemy models for the application.
|
|
|
|
Models:
|
|
- User: User accounts with OAuth support
|
|
- Collection: Player card collections
|
|
- Deck: Player deck configurations
|
|
- CampaignProgress: Single-player campaign state
|
|
- ActiveGame: In-progress game state
|
|
- GameHistory: Completed game records
|
|
|
|
Usage:
|
|
from app.db.models import User, Deck, Collection
|
|
|
|
user = User(
|
|
email="player@example.com",
|
|
display_name="Player1",
|
|
oauth_provider="google",
|
|
oauth_id="123456789"
|
|
)
|
|
"""
|
|
|
|
from app.db.models.campaign import CampaignProgress
|
|
from app.db.models.collection import CardSource, Collection
|
|
from app.db.models.deck import Deck
|
|
from app.db.models.game import ActiveGame, EndReason, GameHistory, GameType
|
|
from app.db.models.oauth_account import OAuthLinkedAccount
|
|
from app.db.models.user import User
|
|
|
|
__all__ = [
|
|
# User
|
|
"User",
|
|
# OAuth
|
|
"OAuthLinkedAccount",
|
|
# Collection
|
|
"Collection",
|
|
"CardSource",
|
|
# Deck
|
|
"Deck",
|
|
# Campaign
|
|
"CampaignProgress",
|
|
# Game
|
|
"ActiveGame",
|
|
"GameHistory",
|
|
"GameType",
|
|
"EndReason",
|
|
]
|