Skip to content

Authentication

Micelclaw OS supports three authentication mechanisms that coexist. Every authenticated request must include an Authorization header.

For programmatic access — skills, sync connectors, and admin scripts.

Authorization: Bearer clk_a1b2c3d4e5f6...

API keys are opaque tokens stored as SHA-256 hashes. The plaintext is shown only once at creation time.

Format: clk_<32-hex-chars>

Scopes:

ScopeIdentity resolutionUse case
agentAlways from api_keys.user_id (ignores headers)Skills running in an agent workspace
systemX-Claw-User-Id header (required in multi-user mode)Sync engine, admin CLI, internal operations
syncSame as systemSync connectors

Management (requires admin role):

  • POST /admin/api-keys — create key { user_id?, scope?, label? } → returns { id, key, key_prefix, scope, ... } (key visible only once)
  • GET /admin/api-keys — list keys ?user_id=...&scope=...
  • DELETE /admin/api-keys/:id — revoke key
  • GET /api-keys/mine — list your own keys

For the dashboard and frontend applications.

Authorization: Bearer <accessToken>
EndpointMethodDescription
/auth/loginPOST{email, password}{accessToken, refreshToken, user}
/auth/refreshPOST{refresh_token}{accessToken, refreshToken}
/auth/setupPOSTCreate initial user (only when 0 users exist)
/auth/logoutPOSTRevoke refresh token

Token lifetime: access token 24h, refresh token 30 days.

JWT payload: {sub: userId, email, role: "owner"|"admin"|"user", iat, exp}

For internal operations during setup and bootstrapping. Generated during initial setup and stored in the environment configuration.

In multi-user mode, the system token requires the X-Claw-User-Id header to identify the target user. In single-user mode, the user context is resolved automatically.

These endpoints do not require a token:

  • GET /auth/status — current mode (setup, single_user, multi_user)
  • POST /auth/setup — create initial user (only if 0 users exist)
  • POST /auth/login — login with email/password
  • POST /auth/register — complete registration with invitation token
  • POST /auth/refresh — rotate tokens
  • POST /auth/logout — revoke refresh token
  • POST /auth/forgot-password — request password reset (always returns 200)
  • POST /auth/reset-password — reset password with {token, new_password}
  • GET /health — health check

The auth middleware detects token type automatically:

  1. If the token matches the system token → system authentication
  2. If the token starts with clk_ → API key lookup (hash in database)
  3. Otherwise → JWT verification

Requests without a valid token receive:

{
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid or missing authentication token"
}
}

Status: 401 Unauthorized