AuthFlow is a modern, enterprise-grade authentication and authorization platform you can self-host. It provides OAuth2/OIDC, JWT tokens, MFA, webhooks, API keys, and complete user management out of the box.
- Overview
- Features
- Tech Stack
- Prerequisites
- Quick Start
- Project Structure
- Configuration
- Running Locally
- API Documentation
- Deployment
- Development
- Troubleshooting
- Support
AuthFlow is a complete authentication solution for modern applications. Instead of building auth from scratch, integrate AuthFlow into your app and get:
- β User registration & login
- β OAuth2 & OpenID Connect (OIDC)
- β Multi-factor authentication (MFA/TOTP)
- β JWT token management
- β API key generation
- β Organization & team management
- β Webhooks for events
- β Audit logs
- β Admin dashboard
- β Email verification
- SaaS Platforms - User management for your application
- Multiple Apps - Single auth provider for multiple services
- Enterprise - Team, organization, and permission management
- Microservices - Centralized auth for service-to-service calls
| Method | Type | Use Case |
|---|---|---|
| Email/Password | Native | Standard username/password auth |
| OAuth2 | Provider | Connect Google, GitHub, etc. |
| OIDC | Provider | Enterprise SSO support |
| MFA (TOTP) | 2-Factor | Security-conscious users |
| API Keys | Programmatic | Service-to-service calls |
- User registration with email verification
- Profile management
- Password reset & change
- Account deactivation & deletion
- Session management & device tracking
- Login history & audit logs
- Create & manage organizations
- Invite team members
- Role-based access control (RBAC)
- Team & permission management
- Organization settings
- Access tokens (short-lived, 15m default)
- Refresh tokens (long-lived, 7d default)
- API key generation with permissions
- Token blacklisting on logout
- Automatic credential rotation
- REST API for all operations
- Webhook events for integration
- SDK libraries (JavaScript, Node.js, React)
- API analytics & usage tracking
- Developer integration guide
- User management dashboard
- Organization oversight
- Audit log viewer
- System analytics
- Application settings
- Runtime: Node.js 18+
- Framework: Express.js 5
- Language: TypeScript 5.9
- Database: MongoDB 4.4+
- Cache: Redis 6+ (optional)
- Email: SMTP / Nodemailer
- Storage: AWS S3 (for file uploads)
- Auth: Passport.js, jsonwebtoken
- Password: bcryptjs
- Jobs: BullMQ (webhook queue)
- Framework: React 19
- Language: TypeScript 5.9
- Build Tool: Vite 7
- Styling: Tailwind CSS 3
- State: Redux Toolkit
- Forms: React Hook Form
- Validation: Zod
- HTTP: Axios
- Icons: Lucide React
- Frontend Hosting: Vercel (recommended)
- Backend: Self-hosted (pm2, Docker, K8s)
- Database: MongoDB Atlas or self-hosted
- Cache: Redis Cloud or self-hosted
Before you begin, ensure you have:
- Docker & Docker Compose (Download)
- MongoDB 4.4+ (local or cloud)
- Redis 6+ (for production)
- Code Editor: VS Code (Download)
- MongoDB Atlas Account - Free tier available
- AWS S3 Account - For file storage (optional)
- SMTP Email Service - Gmail or SendGrid (for email features)
- OAuth Providers - Google & GitHub (optional)
Get AuthFlow running in 5 minutes:
git clone https://github.com/yourusername/authflow.git
cd AuthFlowBackend:
cd backend
npm installFrontend:
cd frontend
npm installBackend (.env)
cd backend
cp .env.example .envEdit backend/.env:
# Server
NODE_ENV=development
PORT=3000
SESSION_SECRET=your-random-secret-key-min-32-chars
# Database
MONGODB_URI=mongodb://localhost:27017/authflow
# Redis (optional)
REDIS_URL=redis://localhost:6379
# Email (optional)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-app-password
# JWT
JWT_SECRET=your-jwt-secret-key
# Frontend URL
FRONTEND_URL=http://localhost:5173
# AWS S3 (optional)
AWS_ACCESS_KEY_ID=your-key
AWS_SECRET_ACCESS_KEY=your-secret
AWS_REGION=us-east-1
S3_BUCKET=authflow-uploadsFrontend (.env.local)
cd frontend
cp .env.example .env.localEdit frontend/.env.local:
VITE_CLIENT_ID=your-client-id-will-generate-after-first-run
VITE_REDIRECT_URI=http://localhost:5173/auth/callback
VITE_AUTHFLOW_BASE_URL=http://localhost:3000
VITE_BACKEND_URL=http://localhost:3001cd backend
npm run devExpected output:
β Server running on http://localhost:3000
β Database connected to MongoDB
In a new terminal:
cd frontend
npm run devExpected output:
β Local: http://localhost:5173
β Ready for development
- Frontend: http://localhost:5173
- API: http://localhost:3000
- API Docs: http://localhost:3000/docs
AuthFlow/
βββ backend/ # Node.js/Express API
β βββ src/
β β βββ app.ts # Express setup
β β βββ server.ts # Server entry
β β βββ config/ # Configuration files
β β β βββ database.ts # MongoDB connection
β β β βββ passport.ts # OAuth strategies
β β β βββ redis.ts # Redis setup
β β β βββ email.ts # Email configuration
β β βββ controllers/ # Route handlers
β β β βββ auth.controller.ts # Auth endpoints
β β β βββ oauth2.controller.ts # OAuth2 flow
β β β βββ mfa.controller.ts # MFA operations
β β β βββ ...
β β βββ routes/ # API routes
β β βββ models/ # MongoDB schemas
β β βββ services/ # Business logic
β β β βββ auth.service.ts # Auth logic
β β β βββ email.service.ts # Email sending
β β β βββ ...
β β βββ middlewares/ # Express middleware
β β β βββ auth.middleware.ts # Token verification
β β β βββ rbac.middleware.ts # Permission checks
β β β βββ ...
β β βββ repositories/ # Database queries
β β βββ utils/ # Helper functions
β β β βββ jwt.ts # Token generation
β β βββ types/ # TypeScript types
β βββ package.json
β βββ tsconfig.json
β βββ .env # Environment variables
β
βββ frontend/ # React application
β βββ src/
β β βββ main.tsx # Entry point
β β βββ app/ # App setup
β β β βββ store.ts # Redux store
β β β βββ apiClient.ts # Axios instance
β β β βββ hooks.ts # Custom hooks
β β βββ features/ # Feature modules
β β β βββ auth/ # Authentication
β β β βββ applications/ # Apps management
β β β βββ organizations/ # Orgs management
β β β βββ apiKeys/ # API key management
β β β βββ webhooks/ # Webhooks
β β β βββ developers/ # Dev integration
β β β βββ ...
β β βββ components/ # Reusable components
β β βββ shared/ # Shared utilities
β β βββ index.css # Global styles
β βββ package.json
β βββ vite.config.ts
β βββ .env.local
β
βββ packages/ # SDK libraries
β βββ authflow-js/ # JavaScript SDK
β βββ authflow-node/ # Node.js SDK
β βββ authflow-react/ # React SDK
β
βββ README.md # This file
| Variable | Required | Default | Description |
|---|---|---|---|
NODE_ENV |
Yes | development |
development or production |
PORT |
No | 3000 |
Server port |
MONGODB_URI |
Yes | - | MongoDB connection string |
REDIS_URL |
No | - | Redis connection (optional) |
JWT_SECRET |
Yes | - | Secret for JWT signing |
SESSION_SECRET |
Yes | - | Secret for sessions |
FRONTEND_URL |
Yes | - | Frontend URL for CORS |
SMTP_HOST |
No | - | Email server host |
SMTP_PORT |
No | 587 |
Email server port |
SMTP_USER |
No | - | Email account |
SMTP_PASSWORD |
No | - | Email password |
| Variable | Required | Default | Description |
|---|---|---|---|
VITE_AUTHFLOW_BASE_URL |
Yes | - | Backend API URL |
VITE_CLIENT_ID |
No | - | OAuth client ID |
VITE_REDIRECT_URI |
No | - | OAuth redirect URL |
Default token expiration (can be changed per application):
// Access Token
expiresIn: 15 * 60; // 15 minutes
// Refresh Token
expiresIn: 7 * 24 * 60 * 60; // 7 days
// Email Verification Token
expiresIn: 24 * 60 * 60; // 24 hours
// Password Reset Token
expiresIn: 1 * 60 * 60; // 1 hourTerminal 1 - Backend:
cd backend
npm run devTerminal 2 - Frontend:
cd frontend
npm run dev# Start all services (backend, frontend, mongodb, redis)
docker-compose up -d
# View logs
docker-compose logs -f backend
docker-compose logs -f frontend
# Stop all services
docker-compose down-
Create Initial Admin User
- Go to http://localhost:5173
- Click "Sign Up"
- Create your account
- Verify email (check console in dev mode)
-
Create First Application
- Login to dashboard
- Go to "Applications"
- Click "Create Application"
- Get your Client ID
-
Generate API Key
- Go to "API Keys"
- Click "Create Key"
- Copy and save the key (shown only once)
-
Start Integration
- Go to "Developer Integration"
- Select your application
- Follow code examples
POST /api/auth/register
Content-Type: application/json
{
"email": "user@example.com",
"password": "SecurePassword123!",
"name": "John Doe",
"organizationName": "My Company"
}POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "SecurePassword123!"
}GET /api/auth/me
Authorization: Bearer {accessToken}POST /api/auth/refresh
Content-Type: application/json
{
"refreshToken": "{refreshToken}"
}POST /api/auth/logout
Authorization: Bearer {accessToken}
Content-Type: application/json
{
"refreshToken": "{refreshToken}"
}POST /api/sdk/auth/register
Content-Type: application/json
{
"client_id": "your_client_id",
"client_secret": "your_client_secret",
"email": "user@example.com",
"password": "SecurePassword123!",
"name": "John Doe"
}GET /api/sdk/token/verify
Authorization: Bearer {userToken}
X-Client-Id: your_client_idVisit http://localhost:3000/docs for complete API reference with all endpoints.
# Install Heroku CLI
npm install -g heroku
# Login
heroku login
# Create app
heroku create your-authflow-app
# Add MongoDB addon
heroku addons:create mongolab:sandbox
# Deploy
git push heroku main# Build image
docker build -t authflow-backend ./backend
# Run container
docker run -p 3000:3000 \
-e MONGODB_URI=mongodb://... \
-e JWT_SECRET=... \
authflow-backend# Install PM2
npm install -g pm2
# Start backend
cd backend
pm2 start npm --name "authflow-api" -- start
# Monitor
pm2 monit
# Save config
pm2 save
pm2 startup# Install Vercel CLI
npm install -g vercel
# Deploy
cd frontend
vercel# Install Netlify CLI
npm install -g netlify-cli
# Deploy
cd frontend
netlify deploy --prod --dir=distUpdate these in your hosting platform:
NODE_ENV=production
MONGODB_URI=mongodb+srv://user:pass@cluster.mongodb.net/authflow
REDIS_URL=redis://user:pass@host:6379
JWT_SECRET=<strong-random-secret>
SESSION_SECRET=<strong-random-secret>
FRONTEND_URL=https://yourdomain.com
SMTP_HOST=smtp.sendgrid.net
SMTP_PORT=587
SMTP_USER=apikey
SMTP_PASSWORD=<sendgrid-api-key># Install dependencies for all packages
npm install
# Install specific workspace
npm install --workspace=backend
npm install --workspace=frontend
npm install --workspace=packages/authflow-react# Backend tests
cd backend
npm run test
# Frontend tests
cd frontend
npm run test# Lint
npm run lint
# Format
npm run format
# Type check
npm run type-check# Feature branch
git checkout -b feature/your-feature
# Commit with message
git commit -m "feat: add your feature"
# Push to remote
git push origin feature/your-feature
# Create Pull Request
# (Go to GitHub and create PR)Error: EADDRINUSE: address already in use :::3000
# Kill process on port 3000
lsof -ti:3000 | xargs kill -9
npm run devError: MONGODB_URI not found
# Set environment variable
export MONGODB_URI=mongodb://localhost:27017/authflow
npm run dev
# Or create .env file
echo "MONGODB_URI=mongodb://localhost:27017/authflow" > .envError: CORS error or Cannot connect to API
# Check VITE_AUTHFLOW_BASE_URL in .env.local
VITE_AUTHFLOW_BASE_URL=http://localhost:3000
# Clear browser cache
# Restart both serversError: Module not found
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
npm run devError: connect ECONNREFUSED 127.0.0.1:27017
# Start MongoDB
# macOS with Homebrew
brew services start mongodb-community
# Docker
docker run -d -p 27017:27017 mongo:latest
# Or use MongoDB Atlas cloudCheck SMTP configuration:
# Test email settings
node -e "
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD
}
});
transporter.verify((err, ok) => {
if (err) console.error(err);
else console.log('Email config OK');
});
"We welcome contributions! Please:
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
- Use TypeScript
- Follow existing patterns
- Write meaningful commit messages
- Add tests for new features
This project is licensed under the MIT License - see LICENSE file for details.
- Documentation: Full docs
- Issues: GitHub Issues
- Email: support@authflow.local
- Community: Discussions
Built with:
- Express.js - Backend framework
- React - Frontend framework
- MongoDB - Database
- TypeScript - Type safety
- Tailwind CSS - Styling
Happy Coding! π
For updates and latest features, keep an eye on the Changelog.