How indominusbyte/fastapi-jwt-auth works
Main Components
a) Core Authentication Components:
• JWT Token Manager
• Configuration Manager
• Exception Handler
• Token Validator/Decoder
b) Integration Components:
• FastAPI Integration Layer
• WebSocket Support
• Cookie Management
• CSRF Protection
┌─────────────────────────────────────────────┐
• Client Application │
• ┬─────────────────────────┘
• ↓
┌─────────────────────────────────────────────┐
• FastAPI Application │
• ┬─────────────────────────┘
• ↓
┌─────────────────────────────────────────────┐
• FastAPI JWT Auth Layer │
• ┬─────────────┬────────────────┤
• Auth JWT │ Config │ Exceptions │
• ┴─────────────┴────────────────┘
Key Relationships to Highlight
a) Token Flow:
• Both symmetric and asymmetric token handling paths
• Denylist/revocation flow
b) Integration Points:
• How the library interfaces with FastAPI's dependency injection system
• WebSocket authentication flow
• Demonstrate cookie-based token storage mechanism
Detailed Component Breakdown
┌─────────────────────────────────────────────────────────┐
• AuthJWT Class │
• ┤
• create_access_token() │
• create_refresh_token() │
• get_jwt() │
• get_raw_jwt() │
• jwt_required() │
• jwt_optional() │
• fresh_jwt_required() │
• jwt_refresh_token_required() │
• ┘
Special Features
• Token Freshness System
• Revocation Mechanism
• Custom Claims Support
• CSRF Protection Flow
• WebSocket Authentication
Implementation Details
• Configuration flow from auth_config.py
• Exception handling pattern from exceptions.py
• Token validation middleware
• Integration with FastAPI's security system
External Dependencies
Connections to:
• PyJWT library
• Redis (for denylist implementation)
• FastAPI security framework
Notes for Implementation
• Use standard UML notation where appropriate
• Notes for important configuration options
• Both synchronous and WebSocket paths
Remember to include version compatibility information and note any critical security considerations in supplementary documentation.
This structure will provide a clear understanding of how the library integrates with FastAPI while maintaining security and providing flexibility for different authentication scenarios.