User Model
Creating a User Entity
Create a user entity that represents your application’s users:User Repository
Framefox automatically generates a repository for your entity:User Provider
Understanding UserProvider
TheUserProvider class retrieves the currently authenticated user:
/home/daytona/workspace/source/framefox/core/security/user/user_provider.py:17
How It Works
TheUserProvider retrieves users from:
- Session cache: Checks session for user ID
- JWT token payload: Extracts user info from token
- Database: Queries repository if needed
- Virtual users: Creates virtual OAuth users
/home/daytona/workspace/source/framefox/core/security/user/user_provider.py:31
Entity User Provider
TheEntityUserProvider resolves the repository and property for user lookup:
/home/daytona/workspace/source/framefox/core/security/user/entity_user_provider.py:25
Configuration
Configure user providers inconfig/security.yaml:
User Badge
TheUserBadge identifies and retrieves users from the database:
/home/daytona/workspace/source/framefox/core/security/passport/user_badge.py:10
Usage in Authentication
Password Hashing
Framefox uses bcrypt for secure password hashing:/home/daytona/workspace/source/framefox/core/security/password/password_hasher.py:12
Hashing Passwords
Verifying Passwords
Role-Based Access Control
Defining Roles
Roles are stored as a list in the user entity:ROLE_USER: Basic authenticated userROLE_ADMIN: Administrator with full accessROLE_MODERATOR: Content moderation accessROLE_EDITOR: Content editing accessIS_AUTHENTICATED_ANONYMOUSLY: Public access
Configuring Access Control
Define access rules inconfig/security.yaml:
How Access Control Works
TheAccessManager evaluates access rules:
/home/daytona/workspace/source/framefox/core/security/access_manager.py:17
Checking Permissions in Controllers
Checking Permissions in Templates
Virtual OAuth Users
Framefox supports virtual users for OAuth authentication without database storage:Creating Virtual Users
/home/daytona/workspace/source/framefox/core/security/passport/passport.py:100
Virtual User Features
- No database required: Users exist only in JWT tokens
- Automatic creation: Created on first OAuth login
- Session persistence: Cached in session for performance
- Role assignment: Can have roles like database users
Detecting Virtual Users
User Registration
Registration Controller
Registration Form
User Profile Management
Update Profile
Change Password
Security Best Practices
1. Always Hash Passwords
2. Use Strong Password Requirements
3. Validate Email Uniqueness
4. Implement Account Activation
5. Use Role Hierarchy
Next Steps
Authentication
Learn about authentication flows and JWT tokens
Security Overview
Explore all security features