Token di sessione e heartbeat

Token Bearer di 30 giorni, verifica periodica e logout automatico alla scadenza.

Panoramica

Dopo una verifica della licenza riuscita, il client desktop deve ottenere un token di sessione tramite POST /api/auth/login. Questo token si usa come header Bearer per tutte le richieste di heartbeat successive a POST /api/auth/heartbeat.

Flusso di login

POST /api/auth/login
Content-Type: application/json

{
  "email": "[email protected]",
  "password": "...",
  "machineId": "sha256-hash",
  "machineName": "DESKTOP-ABC123",
  "appVersion": "1.2.3"
}

Response (200):

{
  "sessionToken": "eyJhbGciOiJIUzI1NiIs...",
  "expiresAt": "2025-01-15T10:30:00Z",
  "license": {
    "plan": "Pro",
    "maxMachines": 3,
    "expiresAt": "2025-12-01T00:00:00Z"
  }
}

Error responses:

  • 401 - Invalid credentials
  • 402 - License expired or payment required
  • 429 - Rate limited (max 5 attempts/min)

Heartbeat

Invia heartbeat ogni 5 minuti per mantenere attiva la sessione e aggiornare LastSeenAt sul server:

POST /api/auth/heartbeat
Authorization: Bearer {sessionToken}
Content-Type: application/json

{
  "machineId": "sha256-hash",
  "appVersion": "1.2.3",
  "ipAddress": "auto"
}

Response (200):

{
  "valid": true,
  "license": { "plan": "Pro", "maxMachines": 3 },
  "serverTime": "2025-01-15T10:30:00Z"
}

If valid: false, the client must immediately lock Pro features and prompt for re-login.

Esci

Al logout esplicito o alla chiusura dell'app, chiama:

POST /api/auth/logout
Authorization: Bearer {sessionToken}

Questo invalida il token di sessione sul server. Il client deve anche cancellare tutte le credenziali salvate.