Skip to main content

Overview

Genie Helper uses Directus as its authentication backend. The API supports three authentication strategies:
  1. Directus JWT - User authentication for client-facing endpoints
  2. Shared Secret - Server-to-server communication (credential encryption)
  3. Admin Token - Internal privileged operations (never exposed to clients)

Directus JWT Authentication

Login Flow

Clients authenticate via the Directus /auth/login endpoint: Request:
Response:

Using the Token

Include the access_token in the Authorization header for all authenticated requests:
Example - Generate Caption:

Token Validation

Endpoints validate tokens by calling Directus /users/me:
If validation fails, the endpoint returns 401 Unauthorized.

Token Refresh

When the access token expires (default TTL: 15 minutes), use the refresh token:
Response:

Shared Secret (X-RBAC-SYNC-SECRET)

Purpose

Server-to-server endpoints that handle sensitive operations (credential encryption/decryption) require a shared secret header instead of user JWT. Endpoints using this method:
  • POST /api/credentials/store
  • POST /api/credentials/reveal
  • POST /api/credentials/reveal-download-cred
  • POST /api/credentials/get-platform-session

Configuration

Set in .env:

Usage

Validation Logic

Never expose RBAC_SYNC_WEBHOOK_SECRET to client-side code. This is strictly for server-to-server communication.

Admin Token (DIRECTUS_ADMIN_TOKEN)

Purpose

Some operations require Directus admin privileges but should not require end-users to be admins:
  1. User registration (/api/register) - Creates users via admin token so public registration doesn’t require open Directus permissions
  2. Credential storage - Writes to platform_connections table via admin token
  3. Queue stats - Reads queue metadata

Configuration

Example - Registration Flow

From register.js:43:
This allows public users to register without requiring directus_users to have public create permissions.
Never expose DIRECTUS_ADMIN_TOKEN in client code or API responses. It grants full database access.

User Role Resolution

Some endpoints verify admin status by checking the authenticated user’s role:

Security Best Practices

  • Store tokens in secure, httpOnly cookies or native secure storage
  • Never store tokens in localStorage (XSS risk)
  • Implement automatic token refresh before expiry
  • Rotate RBAC_SYNC_WEBHOOK_SECRET and DIRECTUS_ADMIN_TOKEN regularly
  • Use different secrets for development/staging/production
  • Never commit secrets to version control
  • Always use HTTPS in production (enable via ENABLE_HTTPS=true)
  • Configure SSL certificates (HTTPS_CERT_PATH, HTTPS_KEY_PATH)
  • Tokens transmitted over HTTP can be intercepted
  • All endpoints validate tokens by calling /users/me (no local JWT verification)
  • This ensures revoked tokens are immediately invalid
  • Adds latency but improves security

Next Steps

Credentials API

Learn how to encrypt and manage platform credentials