1. Quadro generale
- L'utente paga sul sito (Stripe/PayPal). Il server emette una licenza (piano
Pro, idempotente per ordine) con chiaveGRAV-XXXXX-XXXXX-XXXXX-XXXXX. La chiave in chiaro viene mostrata una sola volta nella pagina Download; il server conserva solo il suo hash SHA-256 e non può mai mostrarla di nuovo. - L'utente incolla la chiave nell'app desktop → l'app chiama
/api/license/verifya ogni avvio. La prima verifica registra il computer come attivazione (massimo 3 computer per licenza). - L'app accede anche con le credenziali del sito → riceve un token di sessione Bearer di 30 giorni.
- L'app invia periodicamente heartbeat con quel token; una sessione o licenza scaduta/revocata deve bloccare le funzioni Pro.
Due credenziali: non confonderle mai
| Credenziale | Origine | Scopo | Durata |
|---|---|---|---|
Chiave di licenza GRAV-... | Pagina Download (una sola volta) | Attivazione del computer + verifica | 365 giorni |
| Token di sessione | POST /api/auth/login | Header Bearer per heartbeat/logout | 30 giorni |
2. Convenzioni
- URL di base in sviluppo:
http://localhost:5243(profilo https:https://localhost:7130). Produzione:https://iamgravity.eu - Tutti gli endpoint:
POST,Content-Type: application/json, risposte JSON (camelCase) - Niente cookie/CSRF: le API delle licenze sono anonime; l'autenticazione avviene con campi nel corpo o
Authorization: Bearer <token> - Tutte le date/ore sono UTC ISO-8601; leggile come UTC, mostrale in ora locale
- I rifiuti di licenza restituiscono HTTP 200 con
valid:false— decidi sempre in base al corpo JSON, mai in base al codice di stato
3. Endpoint
3.1 POST /api/license/verify — Controllo di attivazione all'avvio
Richiesta:
{
"licenseKey": "GRAV-XXXXX-XXXXX-XXXXX-XXXXX",
"machineId": "<stable id>",
"machineName": "DESKTOP-ABC123",
"appVersion": "1.0.0"
}
Successo (200):
{
"valid": true,
"reason": "ok",
"license": {
"orderNumber": "PYPL-8XK4321",
"plan": "Pro",
"expiresAt": "2027-10-07T09:26:21Z",
"activations": 1,
"maxActivations": 3
}
}
Failure (also HTTP 200):
{
"valid": false,
"reason": "license_expired",
"message": "Your license has expired. Renew at iamgravity.eu/#pricing."
}
3.2 POST /api/auth/login — Account Login, Returns Session Token
Richiesta:
{
"email": "[email protected]",
"password": "...",
"machineId": "<stable id>",
"machineName": "DESKTOP-ABC123",
"appVersion": "1.0.0"
}
3.3 POST /api/license/heartbeat — Session Keep-Alive
Header: Authorization: Bearer <sessionToken>
{ "machineId": "<stable id>" }
3.4 POST /api/auth/logout — Revoke Session Token
Header: Authorization: Bearer <sessionToken>, empty body → 200 { "success": true }
4. Formato e ciclo di vita della chiave di licenza
Format: GRAV- + 4 groups of 5 chars (--separated, 23 chars total). Alphabet: ABCDEFGHJKLMNPQRSTUVWXYZ23456789 — no I, O, 0, 1 (anti-confusion).
Client-side validation regex:
^GRAV-[A-HJ-NP-Z2-9]{5}-[A-HJ-NP-Z2-9]{5}-[A-HJ-NP-Z2-9]{5}-[A-HJ-NP-Z2-9]{5}$
Lifecycle: Issued on payment success, plan "Pro", valid 365 giorni. Status Active(0) → Expired(2) (auto-flipped) or Revoked(1) (manual). MaxActivations = 3 machines.
5. Requisiti dell'ID del computer
machineId is a client-generated, opaque, stable string. Rules:
- Deterministic — same machine, same ID, across restarts/updates/reinstalls
- Unique per machine — two PCs must never collide
- Recommended recipe (Windows): hex SHA-256 of the registry MachineGuid (
HKLM\\SOFTWARE\\Microsoft\\Cryptography\\MachineGuid) - Do NOT use values that change with hardware dongles, VPNs, MAC randomization, or current username
- Always send
machineName(Environment.MachineName) andappVersion
6. Reason / Error Codes → Required Client Behavior
| Codice | Where | Significato | Client Action |
|---|---|---|---|
ok (valid:true) | verify | Licensed | Unlock Pro features, cache license info |
license_not_found | verify | Key unknown | Re-prompt; link to Download page |
license_revoked | verify | License revoked by staff | Lock; show [email protected] |
license_expired | verify | Past ExpiresAt | Lock; deep-link /pricing to renew |
activation_limit_reached | verify | More than 3 machines | Lock; deep-link account page to revoke a device |
machine_revoked | verify | This device was revoked | Lock; user must re-activate from account page |
session_invalid_or_expired (401) | Heartbeat | Session dead or machine not activated | Silent re-login; if still failing → re-verify, then lock |
no_active_license (402) | Accedi | No active license on account | Lock; deep-link /pricing |
7. Flusso di avvio consigliato
App start
├─ No stored license key → Activation screen (paste key) ─────────────────────────────────────────────────────────────────────────────────────────────│
├─ Stored key: │
│ 1. POST /api/license/verify {key, machineId, ...} ├──────────────────────────────────────────────────────│
│ valid:true → cache license, continue
│ valid:false → show message, LOCK Pro features
│ network error → offline grace
│ 2. POST /api/auth/login {email, password, machineId, ...}
│ 200 → store sessionToken + expiresAt securely
│ 402/401/429 → handle per error codes
│ 3. Start heartbeat timer (every 30–60 min)
└─ Runtime:
heartbeat 200 → refresh cached license info, stay unlocked
heartbeat 401 → silent re-login once; 402 → LOCK
user sign-out / app exit → POST /api/auth/logout (fire-and-forget)
8. Regole di tolleranza offline
If the last successful verify/heartbeat is within N days (recommend 7; max 30 = session lifetime), allow Pro features offline and retry in background with backoff (1h → 6h → 24h). Lock when grace window exceeded or explicit valid:false / 402 arrives.
9. Checklist di archiviazione e sicurezza
sessionToken→ Windows Credential Manager or DPAPI (ProtectedData). Never plaintext on disk, never in logs/telemetry.- Password → Credential Manager only with explicit "remember me"; otherwise memory only.
- License key → local settings file is acceptable (low sensitivity); display masked in UI.
machineId→ compute deterministically or cache after first generation; reuse forever.- Gate ALL Pro features behind a single
IsLicensedservice — no scattered booleans. - Never embed a default/shared license key in the binary.
- Log reason codes (not keys/tokens) for support diagnostics.
10. Client C# di riferimento
public sealed class LicenseApiClient
{
private readonly HttpClient _http;
public string? SessionToken { get; set; }
public LicenseApiClient(string baseUrl)
{
_http = new HttpClient { BaseAddress = new Uri(baseUrl.TrimEnd('/') + "/") };
_http.DefaultRequestHeaders.Accept.Add(new("application/json"));
}
public static string GetMachineId()
{
using var key = Microsoft.Win32.Registry
.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine,
Microsoft.Win32.RegistryView.Registry64)
.OpenSubKey("SOFTWARE\\\\Microsoft\\\\Cryptography");
var guid = (string?)key?.GetValue("MachineGuid")
?? throw new InvalidOperationException("MachineGuid unavailable");
return Convert.ToHexString(System.Security.Cryptography.SHA256.HashData(
System.Text.Encoding.UTF8.GetBytes(guid))).ToLowerInvariant();
}
public async Task VerifyAsync(string licenseKey) { ... }
public async Task LoginAsync(string email, string password) { ... }
public async Task HeartbeatAsync() { ... }
public async Task LogoutAsync() { ... }
}
11. Checklist di integrazione
- [ ] Settings UI to paste the license key (validate shape locally with regex, then send as-is)
- [ ] Deterministic
machineId+machineName+appVersionon every call - [ ] Startup sequence: verify → login → heartbeat timer (30–60 min)
- [ ] Every reason code mapped to a user message + app state
- [ ] Offline grace window with authoritative-lock overrides
- [ ] Silent re-login on
401 session_invalid_or_expired - [ ] Secure token/password storage; masked key display
- [ ] Logout on sign-out/app exit
- [ ] Single
IsLicensedgate for ALL Pro features - [ ] Test matrix: wrong key, expired license, 4th machine, revoked machine, revoked license, session expiry, offline start, rate-limited login