ironlicensing-dotnet/README.md

4.8 KiB

IronLicensing.Client

Software licensing SDK for .NET MAUI applications. Add license validation, activation management, feature gating, and trial support to your apps.

NuGet License: MIT

Installation

dotnet add package IronLicensing.Client

Quick Start

1. Register Services

using IronLicensing.Client.Extensions;

builder.Services.AddIronLicensing(options =>
{
    options.PublicKey = "pk_live_xxxxxxxxxx";
    options.ProductSlug = "my-product";
    options.OfflineGraceDays = 7;
});

2. Validate a License

using IronLicensing.Client;

public class MyViewModel
{
    private readonly ILicenseManager _license;

    public MyViewModel(ILicenseManager license)
    {
        _license = license;
    }

    public async Task ValidateLicenseAsync()
    {
        var result = await _license.ValidateAsync("IRON-XXXX-XXXX-XXXX-XXXX");

        if (result.Success)
        {
            Console.WriteLine($"Licensed! Tier: {result.License.Tier}");
        }
        else
        {
            Console.WriteLine($"Error: {result.ErrorMessage}");
        }
    }
}

3. Feature Gating

// Check if feature is available
if (_license.HasFeature("advanced-reports"))
{
    ShowAdvancedReports();
}

// Or throw if feature is required
_license.RequireFeature("advanced-reports"); // throws LicenseRequiredException

Configuration Options

builder.Services.AddIronLicensing(options =>
{
    // Required
    options.PublicKey = "pk_live_xxxxxxxxxx";
    options.ProductSlug = "my-product";

    // Offline support
    options.OfflineGraceDays = 7;           // Days license is valid offline
    options.RequireSignatureForOffline = true;  // Require signed license for offline

    // API settings
    options.ApiBaseUrl = "https://ironlicensing.com";
    options.HttpTimeout = TimeSpan.FromSeconds(30);

    // In-app purchase URLs
    options.SuccessUrl = "myapp://purchase/success";
    options.CancelUrl = "myapp://purchase/cancel";
});

License Activation

// Activate a license key
var result = await _license.ActivateAsync("IRON-XXXX-XXXX-XXXX-XXXX");

if (result.Success)
{
    // License is now active on this device
    Console.WriteLine($"Activated! {_license.CurrentLicense.ActivationsUsed}/{_license.CurrentLicense.ActivationsMax}");
}

// Deactivate (free up activation slot)
await _license.DeactivateAsync();

Trial Support

// Start a trial
var success = await _license.StartTrialAsync("user@example.com");

if (success)
{
    Console.WriteLine($"Trial started! {_license.TrialDaysRemaining} days remaining");
}

// Check trial status
if (_license.IsTrial)
{
    ShowTrialBanner(_license.TrialDaysRemaining);
}

In-App Purchase

// Start checkout flow
var checkout = await _license.StartPurchaseAsync("tier-id", "customer@example.com");

if (checkout.Success)
{
    // Open checkout URL in browser
    await Launcher.OpenAsync(checkout.CheckoutUrl);
}

Events

// Listen for license changes
_license.LicenseChanged += (sender, args) =>
{
    Console.WriteLine($"License changed from {args.OldLicense?.Status} to {args.NewLicense?.Status}");
};

// Listen for validation results
_license.ValidationCompleted += (sender, args) =>
{
    if (!args.Success)
    {
        Console.WriteLine($"Validation failed: {args.ErrorCode} - {args.ErrorMessage}");
    }
};

License Status

// Quick status checks
bool isLicensed = _license.IsLicensed;  // Active or Trial
bool isTrial = _license.IsTrial;
LicenseStatus status = _license.Status;  // Active, Trial, Expired, Suspended, Revoked

// Full license info
var license = _license.CurrentLicense;
Console.WriteLine($"Tier: {license.Tier}");
Console.WriteLine($"Expires: {license.ExpiresAt}");
Console.WriteLine($"Features: {string.Join(", ", license.Features)}");

Offline Support

Licenses are cached locally with cryptographic signatures for secure offline validation:

  • Grace Period: Configurable days the license is valid without server contact
  • Signature Verification: Optional RSA signature verification for offline licenses
  • Automatic Sync: License is re-validated when connectivity is restored
// Clear cached license
await _license.ClearCacheAsync();

Platform Support

Platform Minimum Version
Android 5.0 (API 21)
iOS 15.0
macOS (Catalyst) 15.0
Windows 10.0.17763.0

License

MIT License - see LICENSE for details.