Overview
Dual Authentication Modes
Asta automatically switches between single-user and multi-user modes:
- Single-user mode: No users in database → Legacy Bearer token or open access
- Multi-user mode: Users exist → JWT authentication with roles
Authentication Flow
Multi-User Mode (JWT)
When users exist in the database:User Registration
New users self-register via the login page:
- Creates user with
userrole (non-admin) - Password hashed with bcrypt
- Returns user object (no token yet)
Single-User Mode (Legacy)
When no users exist in the database:User Roles
- Admin
- User
Admin Role
Permissions:- ✅ Full access to all features
- ✅ Create, edit, delete users
- ✅ Access all settings tabs
- ✅ Configure API keys and integrations
- ✅ Manage skills, agents, cron jobs
- ✅ Execute any command (exec tool)
- ✅ Access all files and directories
- ✅ View system status and logs
- General (full)
- Memories
- Keys
- Models
- Permissions
- Skills
- Agents
- Channels
- Cron
- Spotify
- Network
- Knowledge
- About
Implementation Details
JWT Token Structure
Payload:backend/app/auth_utils.py):
AuthMiddleware
Location:backend/app/auth_middleware.py
Full Middleware Implementation
Full Middleware Implementation
Role-Based Access Control
Helper Functions (backend/app/auth_utils.py):
Per-User Data Isolation
User Memories:User Management API
- Authentication
- User Management (Admin)
- Password Management
POST /api/auth/login
Login with username and password.Request:POST /api/auth/register
Self-registration (creates non-admin user).Request:403- Registration not available (no existing users)409- Username already exists400- Invalid username/password (too short)
GET /api/auth/me
Get current authenticated user.Response:Security Considerations
Password Security
- Passwords hashed with bcrypt (cost factor 12)
- Minimum 4 characters (configurable)
- Never stored or logged in plaintext
- Secure comparison prevents timing attacks
JWT Security
- Signed with HS256 algorithm
- 30-day expiry (configurable)
- Secret key from
JWT_SECRET_KEYenv var - Invalidation on server restart if secret changes
CORS Protection
- CORS middleware wraps auth
- Proper preflight handling
- 401 responses include CORS headers
- Configurable allowed origins
Rate Limiting
- Consider adding rate limiting for login endpoint
- Prevent brute force attacks
- IP-based or user-based limits
- Not currently implemented - can be added via middleware
Migration from Single-User to Multi-User
Migrate USER.md
Default user’s
workspace/USER.md is automatically used for user “default” in single-user mode.For multi-user:Troubleshooting
401 Unauthorized on all requests
401 Unauthorized on all requests
Can't create users
Can't create users
If registration fails with 403:
- No users exist yet (database empty)
- First user must be created directly in database or via special setup
- Username already taken
- Try a different username
Lost admin access
Lost admin access
Database fix:
Token expired immediately
Token expired immediately
Check system time:
- JWT expiry uses UTC time
- Ensure system clock is correct
- Check
expclaim in JWT:
Next Steps
Architecture
Understand how auth fits into Asta’s architecture
API Reference
Full authentication API documentation
Quickstart
Get started with setting up your first user
Security
Security best practices and guidelines