Skip to content

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-jwt

Access User Data

In route templates:

json
{
  "data": {
    "user_id": "&#123;&#123;auth.sub&#125;&#125;",
    "role": "&#123;&#123;auth.role&#125;&#125;"
  }
}

Firebase Authentication

Configuration

json
{
  "firebase": {
    "projectId": "&#123;&#123;env.FIREBASE_PROJECT_ID&#125;&#125;",
    "clientEmail": "&#123;&#123;env.FIREBASE_CLIENT_EMAIL&#125;&#125;",
    "privateKey": "&#123;&#123;env.FIREBASE_PRIVATE_KEY&#125;&#125;"
  }
}

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

MethodEndpointDescription
GET/rbac/rolesList roles
POST/rbac/rolesCreate role
GET/rbac/permissionsList permissions
POST/rbac/assignAssign role

Multi-Factor Authentication

Enable MFA

MFA is automatically enabled when Supabase and JWT are configured.

MFA Endpoints

MethodEndpointDescription
POST/mfa/setupGenerate TOTP secret
POST/mfa/verifyVerify TOTP code
POST/mfa/enableEnable MFA
POST/mfa/disableDisable MFA
GET/mfa/backup-codesGet backup codes

MFA Flow

  1. Call /mfa/setup to get QR code
  2. Scan with authenticator app
  3. Verify code with /mfa/verify
  4. 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

  1. Use strong JWT secrets (32+ characters)
  2. Set appropriate token expiration
  3. Use HTTPS in production
  4. Enable rate limiting
  5. Implement MFA for sensitive operations
  6. Use RBAC for granular access control

Released under the ISC License.