Authentication
Backflow supports JWT, Firebase Auth, and API keys.
JWT Authentication
Configuration
json
{
"jwt": {
"secret": "{{env.JWT_SECRET}}"
}
}Protect Routes
json
{
"path": "/admin/users",
"method": "get",
"requireAuth": true
}Making Requests
bash
curl -X GET http://localhost:3000/admin/users \
-H "Authorization: Bearer <token>"Generate Tokens
bash
npm run generate-jwtAccess User Data
In route templates:
json
{
"data": {
"user_id": "{{auth.sub}}",
"role": "{{auth.role}}"
}
}Firebase Authentication
Configuration
json
{
"firebase": {
"projectId": "{{env.FIREBASE_PROJECT_ID}}",
"clientEmail": "{{env.FIREBASE_CLIENT_EMAIL}}",
"privateKey": "{{env.FIREBASE_PRIVATE_KEY}}"
}
}Use Firebase Auth
json
{
"path": "/profile",
"method": "get",
"authProvider": "firebase"
}Firebase Token
bash
curl -X GET http://localhost:3000/profile \
-H "Authorization: Bearer <firebase-id-token>"Tenant API Keys
API keys are tenant-scoped. The tenant is derived from the key itself - no separate tenant header needed.
Create API Key
Via admin panel or API:
bash
curl -X POST http://localhost:3000/tenant/api-keys \
-H "Authorization: Bearer <admin-token>" \
-d '{"name": "Production API", "scopes": ["*"]}'Response includes the key (shown only once):
json
{
"id": "key-123",
"key": "***",
"prefix": "***",
"name": "Production API",
"scopes": ["*"]
}Use API Key
bash
curl -X GET http://localhost:3000/api/data \
-H "x-api-key: <your-api-key>"No x-tenant-id header needed - tenant is derived from the key automatically.
Key Features
- Securely hashed (original never stored)
- Support scopes for fine-grained access
- Track usage statistics
- Can be rotated with grace period
RBAC (Role-Based Access Control)
Enable RBAC
json
{
"rbac": {
"enabled": true,
"defaultRole": "user"
}
}Protect with Permissions
json
{
"path": "/admin/users",
"method": "delete",
"requireAuth": true,
"requiredPermissions": ["users:delete"]
}Role Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /rbac/roles | List roles |
| POST | /rbac/roles | Create role |
| GET | /rbac/permissions | List permissions |
| POST | /rbac/assign | Assign role |
Multi-Factor Authentication
Enable MFA
MFA is automatically enabled when Supabase and JWT are configured.
MFA Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /mfa/setup | Generate TOTP secret |
| POST | /mfa/verify | Verify TOTP code |
| POST | /mfa/enable | Enable MFA |
| POST | /mfa/disable | Disable MFA |
| GET | /mfa/backup-codes | Get backup codes |
MFA Flow
- Call
/mfa/setupto get QR code - Scan with authenticator app
- Verify code with
/mfa/verify - Enable with
/mfa/enable
Tenant Authentication
Tenant identity is derived from authentication:
API Key Auth: Tenant derived automatically from the API key
bash
curl -X GET http://localhost:3000/api/data \
-H "x-api-key: <your-api-key>"Token Auth: Tenant from claims in JWT/Firebase token
bash
curl -X GET http://localhost:3000/api/data \
-H "Authorization: Bearer <token>"Security Best Practices
- Use strong JWT secrets (32+ characters)
- Set appropriate token expiration
- Use HTTPS in production
- Enable rate limiting
- Implement MFA for sensitive operations
- Use RBAC for granular access control