This system supports multiple authentication methods configurable via environment variables (.env).
It can operate in internal-only, partner-only, or hybrid mode.
Additionally, Superadmin authentication is always enabled and bypasses standard authentication checks.
Authentication mode is set in the .env file:
AUTH_MODE=both # Options: internal | partner | bothModes:
internal→ Only API Key authentication is enabled.partner→ Only OAuth2 (JWT) authentication is enabled.both→ Both methods are accepted. OAuth2 is attempted first; if it fails, API Key authentication is checked.
Superadmin provides unrestricted privileged access to all endpoints.
This authentication is always active, regardless of the AUTH_MODE setting.
- Requests must include the query parameter
superAdminKey. - This key must match the configured value in
.env:
SUPER_ADMIN_API_KEY=your-superadmin-secretOn application startup:
- A Superadmin tenant and client are automatically created in the database.
- This account bypasses all standard restrictions and policies.
Designed for internal and trusted systems.
Clients authenticate using an API key passed in the request headers:
X-API-Key: <your-secret-api-key>
Used for external or partner integrations.
Clients authenticate by passing a JWT token in the request header:
Authorization: Bearer <jwt-token>
- Algorithm: RS256
- Signing keys: Retrieved from the tenant’s JWKS (JSON Web Key Set).
- Expiration: Configurable via
.env:
ACCESS_TOKEN_EXPIRE_MINUTES=60 # Default expiry time in minutesExample:
ACCESS_TOKEN_EXPIRE_MINUTES=30| Mode | Method | Header Example |
|---|---|---|
| Internal | API Key | X-API-Key: mySecretInternalKey123 |
| Partner | OAuth2 (JWT) | Authorization: Bearer eyJhbGciOi... |
| Both | OAuth2, fallback to API Key | OAuth2 validated first, API Key if it fails |
The authentication system is structured around three entity levels:
- Tenant → Represents an organization, owning multiple clients.
- Client → Represents an application within a tenant. Issues API keys.
- API Key → Represents credentials tied to a client.
-
Initial State:
When a tenant is created, it is provisioned in an inactive state by default.- Inactive tenants cannot authenticate requests.
- All Clients and API Keys under an inactive tenant are also considered effectively disabled until activation.
-
Activation:
Only a Super Admin has the authority to activate or deactivate a tenant.- Once activated, the tenant and its dependent Clients and API Keys are eligible to operate subject to their policies.
- A deactivated tenant will immediately suspend access for all dependent resources.
-
Operational Impact:
- Inactive Tenant: Rejects all requests with an authentication error (e.g.,
403 Forbidden - Tenant Inactive). - Active Tenant: Policies (IP, scope, rate limits) are evaluated as described below.
- Inactive Tenant: Rejects all requests with an authentication error (e.g.,
Access policies control authentication across Tenant, Client, and API Key levels. All levels support:
-
IP Restrictions
Restrict calls by IP. Supported formats:- Exact IP:
192.168.0.10 - CIDR:
192.168.0.0/24 - Wildcard:
10.0.*.* - Range:
192.168.0.50-192.168.0.100 - Any (
*) → Not recommended in production.
- Exact IP:
-
Scope Restrictions (Required for Endpoint Access)
Each API endpoint requires specific scopes. A token or API key must include the matching scope to access the endpoint. For example:all→ Full system-wide accesstenant→ Tenant-level operationsqdrant→ Vector database APIsmeal_plan→ Meal plan-related APIsgenerate→ Meal plan generation servicesvalidate→ Meal plan validation APIsversion_service→ Version management endpoints
Important: Authentication alone is not sufficient; the credential must also carry the required scope for the requested endpoint.
-
Rate Limits
Restrict the number of requests allowed in a given timeframe per credential.
Policies are hierarchical and cumulative:
- API Key access → Policies of API Key, Client, and Tenant all apply.
- Client access → Controlled by Client and Tenant policies.
- Tenant access → Global restrictions apply across all Clients and API Keys.
- Check Tenant State: If tenant is inactive → deny request.
- Apply Hierarchical Policies: If tenant is active → evaluate restrictions from Tenant, Client, and API Key.
- Verify Required Scope: Explicit matching scope must be present.
- Enforce Rate Limits.
- Authentication can be configured as internal, partner, or both.
- Superadmin authentication (via
SUPER_ADMIN_API_KEY) bypasses all restrictions. - Internal systems use API Key authentication.
- Partner systems use OAuth2 JWT-based authentication.
- All account models (Tenant, Client, API Key) support policies for IP restrictions, scope restrictions, and rate limiting.
- Scopes are required to access endpoints — credentials without the correct scope will be denied, even if authentication succeeds.
- Policies cascade hierarchically: Tenant → Client → API Key.