- Implement OAuth 2.0 and PAT authentication methods - Add user management, roles, and profile functionality - Add database migrations and admin user scripts - Update services for authentication and user settings - Add protected routes and permission hooks - Update documentation for authentication and database access
4.0 KiB
4.0 KiB
Authentication System Implementation Status
✅ Completed Features
Backend
- ✅ Database schema with users, roles, permissions, sessions, user_settings, email_tokens tables
- ✅ User service (CRUD, password hashing, email verification, password reset)
- ✅ Role service (dynamic role and permission management)
- ✅ Auth service (local auth + OAuth with database-backed sessions)
- ✅ Email service (Nodemailer with SMTP)
- ✅ Encryption service (AES-256-GCM for sensitive data)
- ✅ User settings service (Jira PAT, AI features, API keys)
- ✅ Authorization middleware (requireAuth, requireRole, requirePermission)
- ✅ All API routes protected with authentication
- ✅ Auth routes (login, logout, password reset, email verification, invitations)
- ✅ User management routes (admin only)
- ✅ Role management routes
- ✅ User settings routes
- ✅ Profile routes
Frontend
- ✅ Auth store extended with roles, permissions, local auth support
- ✅ Permission hooks (useHasPermission, useHasRole, usePermissions)
- ✅ ProtectedRoute component
- ✅ Login component (local login + OAuth choice)
- ✅ ForgotPassword component
- ✅ ResetPassword component
- ✅ AcceptInvitation component
- ✅ UserManagement component (admin)
- ✅ RoleManagement component (admin)
- ✅ UserSettings component
- ✅ Profile component
- ✅ UserMenu with logout and profile/settings links
- ✅ Feature gating based on permissions
🔧 Configuration Required
Environment Variables
Required for local authentication:
LOCAL_AUTH_ENABLED=true
Required for email functionality:
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=your-email@example.com
SMTP_PASSWORD=your-password
SMTP_FROM=noreply@example.com
Required for encryption:
ENCRYPTION_KEY=your-32-byte-encryption-key-base64
Optional - Initial admin user:
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=SecurePassword123!
ADMIN_USERNAME=admin
ADMIN_DISPLAY_NAME=Administrator
Password requirements:
PASSWORD_MIN_LENGTH=8
PASSWORD_REQUIRE_UPPERCASE=true
PASSWORD_REQUIRE_LOWERCASE=true
PASSWORD_REQUIRE_NUMBER=true
PASSWORD_REQUIRE_SPECIAL=false
Session duration:
SESSION_DURATION_HOURS=24
📝 Notes
JIRA_AUTH Settings
JIRA_PATcan be removed from global env - users configure their own PAT in settingsJIRA_OAUTH_CLIENT_IDandJIRA_OAUTH_CLIENT_SECRETare still needed for OAuth flowJIRA_HOSTandJIRA_SCHEMA_IDare still needed (infrastructure settings)
AI API Keys
ANTHROPIC_API_KEYcan be removed from global env - users configure their own keysOPENAI_API_KEYcan be removed from global env - users configure their own keysTAVILY_API_KEYcan be removed from global env - users configure their own keys- These are now stored per-user in the
user_settingstable (encrypted)
Authentication Flow
- On first run, migrations create database tables
- If
ADMIN_EMAILandADMIN_PASSWORDare set, initial admin user is created - Once users exist, authentication is automatically required
- Users can log in with email/password (local auth) or OAuth (if configured)
- User menu shows logged-in user with links to Profile and Settings
- Logout is available for all authenticated users
🚀 Next Steps
- Set
LOCAL_AUTH_ENABLED=truein environment - Configure SMTP settings for email functionality
- Generate encryption key:
openssl rand -base64 32 - Set initial admin credentials (optional)
- Run the application - migrations will run automatically
- Log in with admin account
- Create additional users via User Management
- Configure roles and permissions as needed
⚠️ Important
- Once users exist in the database, authentication is automatically required
- Service account mode only works if no users exist AND local auth is not enabled
- All API routes are protected - unauthenticated requests return 401
- User-specific settings (Jira PAT, AI keys) are encrypted at rest