New: Offline-first licensing with cryptographic validation. Learn more

Licenses

Licenses are the core building block of Licenz. Learn about the different license types, how they're structured, and how to use the powerful features system.

License Types

Licenz supports three primary license types, each designed for different business models:

Perpetual

One-time purchase with no expiration. Customer owns the license forever. Ideal for desktop software and traditional licensing models.

Subscription

Time-limited license that requires periodic renewal. Perfect for SaaS, recurring revenue models, and continuous update delivery.

Trial

Short-term evaluation license with automatic expiration. Great for letting customers try before they buy with optional feature restrictions.

Choosing the Right Type

License Type Best For Expires Renewals
Perpetual Desktop apps, one-time purchases Never Optional maintenance
Subscription SaaS, continuous updates Monthly/Yearly Required for access
Trial Evaluations, demos 7-30 days typical Convert to paid

License Data Structure

Every license in Licenz follows a consistent JSON structure that contains all the information needed for validation and feature gating:

{
  "id": "lic_abc123def456",
  "key": "LIC-XXXX-XXXX-XXXX-XXXX",
  "product_id": "prod_xyz789",
  "type": "subscription",
  "status": "active",
  "licensee": {
    "email": "customer@example.com",
    "name": "John Doe",
    "company": "Acme Corp"
  },
  "features": ["pro", "api-access", "priority-support"],
  "limits": {
    "max_activations": 3,
    "max_seats": 10
  },
  "metadata": {
    "order_id": "ORD-12345",
    "subscription_tier": "business"
  },
  "issued_at": "2024-01-15T10:30:00Z",
  "expires_at": "2025-01-15T10:30:00Z",
  "signature": "base64_encoded_signature..."
}

Key Fields Explained

  • id - Unique identifier for the license (used in API calls)
  • key - The customer-facing license key they enter
  • product_id - Links the license to a specific product
  • type - One of perpetual, subscription, or trial
  • status - Current state: active, expired, revoked, suspended
  • licensee - Customer information (email, name, company)
  • features - Array of enabled feature flags
  • limits - Numeric limits (activations, seats, API calls, etc.)
  • metadata - Custom key-value data for your business logic
  • signature - Cryptographic signature for offline validation

Features System

The features system lets you create tiered products and control access to specific functionality based on the license.

Defining Features

Features are defined at the product level in your dashboard:

  1. Go to Products and select your product
  2. Navigate to the Features tab
  3. Add feature keys like pro, api-access, export
  4. Optionally add descriptions and limits

Feature Gating in Code

use licenz::{License, Verifier};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let license = License::from_key("LIC-XXXX-XXXX-XXXX-XXXX")?;
    let result = verifier.verify(&license)?;

    // Check for specific features
    if result.has_feature("pro") {
        enable_pro_features();
    }

    if result.has_feature("api-access") {
        enable_api_endpoints();
    }

    // Get all enabled features
    for feature in result.features() {
        println!("Enabled: {}", feature);
    }

    // Check feature limits
    if let Some(max_seats) = result.limit("max_seats") {
        println!("Seats allowed: {}", max_seats);
    }

    Ok(())
}

Feature Best Practices

  • Use descriptive, lowercase feature names with hyphens: api-access, advanced-reports
  • Group related features with prefixes: export-csv, export-pdf, export-excel
  • Keep feature names stable - changing them requires updating deployed applications
  • Use limits for quantitative restrictions (seats, API calls) rather than separate features

Feature Versioning

When deprecating features, keep them in your product definition for backward compatibility. Old licenses will still reference the old feature names.

Trial Licenses

Trials are a special case designed for customer evaluation. They work like subscriptions but with additional restrictions:

# Create a 14-day trial license
licenz license create \
  --product prod_abc123 \
  --email trial@example.com \
  --type trial \
  --trial-days 14 \
  --features "pro"  # Limited features for trial

# Convert trial to paid license
licenz license upgrade LIC-TRIAL-XXXX \
  --type subscription \
  --expires 2025-12-31 \
  --features "pro,api-access,export"

Trial-Specific Features

  • Automatic expiration - Trials expire after the specified period with no grace period
  • Conversion tracking - Monitor trial-to-paid conversion rates in the dashboard
  • Extension rules - Configure whether trials can be extended and by how much
  • Hardware binding - Optionally bind trials to hardware to prevent repeated trials
  • Feature restrictions - Limit trial licenses to a subset of features

License Lifecycle

Licenses move through different states during their lifetime:

Active
Expired
Revoked
  • Active - License is valid and can be used
  • Expired - Past expiration date, can be renewed (subscription/trial)
  • Suspended - Temporarily disabled (payment issues, abuse)
  • Revoked - Permanently disabled (refund, violation)

Next Steps