Authentication Architecture
The authentication flow involves several key components:- Authenticator: Handles the authentication logic
- Passport: Contains user credentials and authentication state
- Firewall: Defines authentication rules for URL patterns
- TokenManager: Manages JWT token creation and validation
- UserProvider: Retrieves authenticated user information
Configuring Authentication
Basic Setup
Configure authentication inconfig/security.yaml:
Multiple Firewalls
You can configure multiple firewalls for different parts of your application:Creating an Authenticator
Form-Based Authenticator
Create a custom authenticator by extendingAbstractAuthenticator:
/home/daytona/workspace/source/framefox/core/security/authenticator/abstract_authenticator.py:20
Understanding Passports
ThePassport class holds authentication information:
/home/daytona/workspace/source/framefox/core/security/passport/passport.py:30
Authentication Flow
The passport authenticates the user in several steps:- User Lookup: Finds user by identifier (email, username, etc.)
- Password Verification: Validates password using bcrypt
- Role Assignment: Assigns user roles from the database
/home/daytona/workspace/source/framefox/core/security/passport/passport.py:45
Login & Logout Flows
Login Flow
- User submits login form to
login_path - Firewall intercepts the request
- CSRF token is validated
- Authenticator extracts credentials and creates passport
- Passport authenticates user against database
- Brute force protection checks are applied
- JWT token is created and stored
- User is redirected to
default_target_path
Logout Flow
- User accesses
logout_path - Firewall handles the logout request
- Token is cleared from storage
- Session is deleted
- Cookies are removed
- User is redirected to login page
/home/daytona/workspace/source/framefox/core/security/handlers/firewall_handler.py:382
Session Management
JWT Tokens
Framefox uses JWT tokens for session management:/home/daytona/workspace/source/framefox/core/security/token_manager.py:28
Token Validation
/home/daytona/workspace/source/framefox/core/security/token_manager.py:59
Token Storage
Tokens are stored in cookies and can be accessed viaTokenStorage:
JWT Stateless Authentication
For API endpoints, use stateless JWT authentication:API Authentication Example
OAuth Authentication
Framefox supports OAuth authentication for third-party providers:/home/daytona/workspace/source/framefox/core/security/authenticator/abstract_oauth_authenticator.py:1
Security Considerations
1. Password Security
2. Token Security
- Tokens are signed with
SESSION_SECRET_KEY - Tokens expire after 1 hour (configurable)
- Tokens are stored in HTTP-only cookies
- Use HTTPS in production
3. Brute Force Protection
- Progressive delays after failed attempts
- IP blocking after 25 attempts/hour
- Account locking after 15 attempts/hour
/home/daytona/workspace/source/framefox/core/security/protector/brute_force_protector.py:39
4. Timing Attack Protection
Next Steps
User Management
Learn about user models and providers
CSRF Protection
Implement CSRF protection in your forms