Authentication
The Ellemment Stack provides robust authentication using web standards and established libraries. The authentication system is designed to be both secure and flexible, offering multiple authentication mechanisms out of the box.
Authentication Methods
The stack offers two primary mechanisms for authentication:
- Username and password authentication
- Provider authentication (SSO)
Email-Password Authentication Process
When a user wishes to sign up for an account, they go through a secure verification process:
Initial Signup
- Users provide their email address through the signup form
- The system generates:
- A verification code using TOTP (Time-based One Time Password)
- A secure magic link
Email Verification
The system sends an email containing:
- The generated verification code
- The magic link
- Instructions for both verification methods
Users can verify their email through either:
- Entering the verification code on the verification page
- Clicking the magic link in their email
Account Setup
After successful verification, users complete the onboarding flow by:
- Setting their username
- Creating a secure password
- Optionally enabling additional security features
The password is securely hashed using the bcrypt algorithm with appropriate salt rounds for maximum security.
Provider Authentication (SSO)
The stack includes a comprehensive system for third-party authentication, built using remix-auth
. This enables easy integration of various SSO options.
Supported Authentication Providers
- OAuth2 providers using
remix-auth
- OpenID Connect providers via
web-oidc
- SAML support through
@boxyhq/remix-auth-sso
GitHub OAuth Integration
The stack comes pre-configured with GitHub OAuth2 authentication. Here's how to set it up:
Local Development Setup
-
Create a GitHub OAuth application:
- Go to GitHub Developer Settings > OAuth Apps
- Click "Register a new application"
- Set Homepage URL to
http://localhost:3000
- Set Authorization callback URL to
http://localhost:3000/auth/github/callback
- Choose a meaningful application name
- Save the application
-
Configure Environment Variables:
# .env file GITHUB_CLIENT_ID="your_client_id" GITHUB_CLIENT_SECRET="your_client_secret"
Development Testing
The system includes a mock GitHub server for development using MSW (Mock Service Worker):
- Set
GITHUB_CLIENT_ID
toMOCK_...
to use the mock server - This intercepts GitHub OAuth requests during development
- Enables testing without real GitHub credentials
Production Configuration
For production environments:
-
Create separate OAuth applications for each environment:
- Development
- Staging
- Production
-
Use appropriate callback URLs for each environment:
Development: http://localhost:3000/auth/github/callback Staging: https://staging.yourapp.com/auth/github/callback Production: https://yourapp.com/auth/github/callback
-
Configure environment-specific secrets in your deployment platform
Two-Factor Authentication (2FA)
The stack implements a robust Two-Factor Authentication system using Time-based One-Time Passwords (TOTP).
TOTP Implementation
The TOTP system provides:
- Secure secret generation and storage
- Time-based code validation
- Support for multiple verification flows
Security Features
-
Verification Types:
- Standard 2FA authentication
- Email verification codes
- Password reset verification
- Email change verification
-
Security Measures:
- 2-hour time limit on 2FA verifications
- Required for sensitive operations
- Secure secret storage in database
- Protection against brute force attacks
Required 2FA Actions
Users with 2FA enabled must verify within a 2-hour window for:
- Changing email address
- Disabling 2FA
- Other destructive actions
- Password changes
- Account deletion
Implementation Details
The TOTP system stores verification data in a dedicated database model with:
- Encrypted secrets
- Expiration timestamps
- Usage tracking
- Automatic cleanup of expired codes
Session Management
The authentication system uses a sophisticated session management approach:
Session Features
-
Secure Storage:
- HTTP-only cookies
- Encrypted session data
- Database-backed sessions
-
Session Controls:
- Individual session revocation
- Multi-device session tracking
- Automatic expiration
- Last-used tracking
-
Security Measures:
- CSRF protection
- Rate limiting
- Secure cookie settings
- Session fixation prevention
Session Database Model
Sessions are stored in a dedicated database table with:
- Unique session identifiers
- User associations
- Creation timestamps
- Last accessed timestamps
- Device information
- Automatic cleanup of expired sessions
Security Best Practices
The authentication system implements several security best practices:
-
Password Security:
- Bcrypt hashing
- Password strength requirements
- Brute force protection
- Secure password reset flow
-
Email Security:
- Verified email addresses
- Secure email change process
- Rate limited email actions
-
Session Security:
- Short-lived sessions
- Secure session storage
- Session revocation
- Cross-site request forgery protection
-
Rate Limiting:
- Login attempts
- Password reset requests
- Email verification attempts
- 2FA attempts
For more detailed information about security measures, visit the security documentation. For deployment configuration details, check the deployment guide.