206 lines
4.8 KiB
Markdown
206 lines
4.8 KiB
Markdown
# IronLicensing.Client
|
|
|
|
Software licensing SDK for .NET MAUI applications. Add license validation, activation management, feature gating, and trial support to your apps.
|
|
|
|
[](https://www.nuget.org/packages/IronLicensing.Client)
|
|
[](https://opensource.org/licenses/MIT)
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
dotnet add package IronLicensing.Client
|
|
```
|
|
|
|
## Quick Start
|
|
|
|
### 1. Register Services
|
|
|
|
```csharp
|
|
using IronLicensing.Client.Extensions;
|
|
|
|
builder.Services.AddIronLicensing(options =>
|
|
{
|
|
options.PublicKey = "pk_live_xxxxxxxxxx";
|
|
options.ProductSlug = "my-product";
|
|
options.OfflineGraceDays = 7;
|
|
});
|
|
```
|
|
|
|
### 2. Validate a License
|
|
|
|
```csharp
|
|
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
|
|
|
|
```csharp
|
|
// 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
|
|
|
|
```csharp
|
|
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
|
|
|
|
```csharp
|
|
// 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
|
|
|
|
```csharp
|
|
// 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
|
|
|
|
```csharp
|
|
// 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
|
|
|
|
```csharp
|
|
// 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
|
|
|
|
```csharp
|
|
// 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
|
|
|
|
```csharp
|
|
// 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 |
|
|
|
|
## Links
|
|
|
|
- [Documentation](https://www.ironlicensing.com/docs)
|
|
- [Dashboard](https://www.ironlicensing.com)
|
|
|
|
## License
|
|
|
|
MIT License - see [LICENSE](LICENSE) for details.
|