Skip to content

Repository files navigation

LicenseChain Unity SDK

LicenseUnityC#Package Manager

Official Unity SDK for LicenseChain - Secure license management for Unity games and applications.

🚀 Features

  • 🔐 Secure Authentication - User registration, login, and session management
  • 📜 License Management - Create, validate, update, and revoke licenses
  • 🛡 Hardware ID Validation - Prevent license sharing and unauthorized access
  • 🔔 Webhook Support - Real-time license events and notifications
  • 📊 Analytics Integration - Track license usage and performance metrics
  • ⚡ High Performance - Optimized for Unity's runtime
  • 🔄 Async Operations - Non-blocking HTTP requests and data processing
  • 🛠 Easy Integration - Simple API with comprehensive documentation

License assertion JWT (RS256 + JWKS)

API base:https://api.licensechain.app/v1

Successful POST /v1/licenses/verify may include license_token, license_token_expires_at, and license_jwks_uri. The JWT must carry token_use = licensechain_license_v1.

RS256 + JWKS: Verify using keys from GET /v1/licenses/jwks (or the returned license_jwks_uri). For tamper-sensitive titles, prefer backend verification; in-client, Unity mirrors the C# stack.

Unity: Add System.IdentityModel.Tokens.Jwt (and dependencies) and follow LicenseAssertion.VerifyLicenseAssertionJwtAsync in LicenseChain-CSharp-SDK (see examples/jwks_only/), or verify on your backend. See THIN_CLIENT_PARITY, JWKS_EXAMPLE_PRIORITY, and the operator quickref JWKS_THIN_CLIENT_QUICKREF.

📦 Installation

Method 1: Unity Package Manager (Recommended)

  1. Open Unity Package Manager
  2. Click the "+" button
  3. Select "Add package from git URL"
  4. Enter: https://github.com/LicenseChain/LicenseChain-Unity-SDK.git

Method 2: Manual Installation

  1. Download the latest release from GitHub Releases
  2. Extract the .unitypackage file
  3. Import the package into your Unity project
  4. Place the LicenseChain folder in your Assets directory

Method 3: Git Submodule

# Add as submodule
git submodule add https://github.com/LicenseChain/LicenseChain-Unity-SDK.git Assets/LicenseChain
# Update submodule
git submodule update --init --recursive

🚀 Quick Start

Basic Setup

usingLicenseChain.Unity;publicclassLicenseManager:MonoBehaviour{privateLicenseChainApiV1Clientclient;voidStart(){varconfig=newLicenseChainConfig{ApiKey="your-api-key",BaseUrl="https://api.licensechain.app/v1",Timeout=30000,Retries=3};client=newLicenseChainApiV1Client(config);}asyncvoidOnDestroy(){client?.Dispose();}}

User Authentication

// Register a new user and fetch profilepublicasyncvoidRegisterAndLoadProfile(stringemail,stringpassword){awaitclient.RegisterUserAsync(email,password,"Unity User");varprofile=awaitclient.GetCurrentUserAsync();Debug.Log(profile.ToString());}

License Management

// Create a license under an app and validate itpublicasyncvoidCreateAndValidateLicense(stringappId,stringemail){varcreated=awaitclient.CreateLicenseAsync(appId,email,"Unity User");varkey=created["licenseKey"]?.ToString();varvalidation=awaitclient.ValidateLicenseAsync(key,appId);Debug.Log(validation.ToString());}

Health Check

publicasyncvoidCheckHealth(){varhealth=awaitclient.HealthAsync();Debug.Log(health.ToString());}

Legacy Compatibility Surface

LicenseChainManager is preserved only for older non-v1 integrations that post actions such as init, login, license, and chatget to the root API host.

New Unity integrations should use LicenseChainApiV1Client and the API v1 examples in this repository.

The legacy manager was intentionally not normalized to https://api.licensechain.app/v1, because changing its transport shape would alter a separate compatibility surface rather than the supported API v1 client.

📚 API Reference

LicenseChainApiV1Client

Constructor

varconfig=newLicenseChainConfig{ApiKey="your-api-key",BaseUrl="https://api.licensechain.app/v1",Timeout=30000,Retries=3};varclient=newLicenseChainApiV1Client(config);

Methods

User Authentication
varregisterTask=client.RegisterUserAsync(email,password,"Unity User");varuserTask=client.GetCurrentUserAsync();
License Management
varcreateTask=client.CreateLicenseAsync(appId,issuedEmail,issuedTo);varvalidateTask=client.ValidateLicenseAsync(licenseKey,appId);varrevokeTask=client.RevokeLicenseAsync(licenseId,"manual revoke");varactivateTask=client.ActivateLicenseAsync(licenseId);varextendTask=client.ExtendLicenseAsync(licenseId,"2027-01-01T00:00:00Z");
Analytics
varanalyticsTask=client.GetAnalyticsStatsAsync(appId,"30d");varusageTask=client.GetUsageStatsAsync(appId,"30d");varlicenseAnalyticsTask=client.GetLicenseAnalyticsAsync(licenseId);

🔧 Configuration

Unity Settings

Configure the SDK through Unity's Project Settings or a configuration file:

// Assets/LicenseChain/Config/LicenseChainSettings.asset[CreateAssetMenu(fileName="LicenseChainSettings",menuName="LicenseChain/Settings")]publicclassLicenseChainSettings:ScriptableObject{[Header("API Configuration")]publicstringapiKey;publicstringbaseUrl="https://api.licensechain.app/v1";[Header("Advanced Settings")]publicinttimeout=30;publicintretries=3;publicbooldebug=false;}

Environment Variables

Set these in your build process or through Unity Cloud Build:

# Requiredexport LICENSECHAIN_API_KEY=your-api-key
# Optionalexport LICENSECHAIN_BASE_URL=https://api.licensechain.app/v1
export LICENSECHAIN_DEBUG=true

Advanced Configuration

varconfig=newLicenseChainConfig{ApiKey="your-api-key",BaseUrl="https://api.licensechain.app/v1",Timeout=30000,// Request timeout in millisecondsRetries=3,// Number of retry attemptsEnableLogging=true,UserAgent="MyGame/1.0.0"// Custom user agent};

🛡 Security Features

Secure Communication

  • All API requests use HTTPS
  • API keys are securely stored and transmitted
  • Webhook signatures are verified

License Validation

  • Real-time license validation
  • Expiration checking

📊 Analytics and Monitoring

Stats Queries

varstats=awaitclient.GetAnalyticsStatsAsync(appId,"30d");varusage=awaitclient.GetUsageStatsAsync(appId,"30d");Debug.Log(stats.ToString());Debug.Log(usage.ToString());

🔄 Error Handling

Custom Exception Types

try{varresult=awaitclient.ValidateLicenseAsync("invalid-key",appId);}catch(NetworkExceptionex){Debug.LogError($"Network connection failed: {ex.Message}");}catch(ApiExceptionex){Debug.LogError($"API failed with {ex.StatusCode}: {ex.Message}");}catch(LicenseChainExceptionex){Debug.LogError($"LicenseChain error: {ex.Message}");}

Retry Logic

// Automatic retry for network errorsvarconfig=newLicenseChainConfig{ApiKey="your-api-key",Retries=3,// Retry up to 3 timesTimeout=30000// Wait up to 30 seconds for each request};

🧪 Testing

Unit Tests

# Run tests in Unity Test Runner# Or via command line
Unity -batchmode -quit -projectPath . -runTests -testResults results.xml

Integration Tests

# Test with real API# Use Unity Test Runner with integration test category

📝 Examples

See the Examples/ directory for complete examples:

  • LicenseChainExample.cs - Basic SDK usage
  • AdvancedLicenseChainExample.cs - Advanced API v1 usage

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Clone the repository
  2. Install Unity 2021.3 or later
  3. Open the project in Unity
  4. Install dependencies
  5. Run tests in Unity Test Runner

📄 License

This project is licensed under the Elastic License 2.0 (ELv2) — see the LICENSE file for details.

🆘 Support

🔗 Related Projects


Made with ❤️ for the Unity community

API Endpoints

Use the canonical API base URL https://api.licensechain.app/v1 for the API v1 client. The REST client also accepts the root host and normalizes requests to the same API version.

Base URL

Available Endpoints

MethodEndpointDescription
GET/v1/healthHealth check
POST/v1/auth/registerUser registration
GET/v1/auth/meCurrent authenticated user
GET/v1/appsList applications
POST/v1/apps/:id/licensesCreate license for app
POST/v1/licenses/verifyVerify license
PATCH/v1/licenses/:id/revokeRevoke license
PATCH/v1/licenses/:id/activateActivate license
PATCH/v1/licenses/:id/extendExtend license
GET/v1/webhooksList webhooks
POST/v1/webhooksCreate webhook
GET/v1/analytics/statsGet analytics

Note: The SDK automatically prepends /v1 to all endpoints, so you only need to specify the path (e.g., /auth/login instead of /v1/auth/login).

LicenseChain API (v1)

This SDK targets the LicenseChain HTTP API v1 implemented by the LicenseChain API service.

  • Production base URL:https://api.licensechain.app/v1
  • API reference:docs.licensechain.app
  • Baseline REST mapping (documented for integrators):
    • GET /health
    • POST /auth/register
    • POST /licenses/verify
    • PATCH /licenses/:id/revoke
    • PATCH /licenses/:id/activate
    • PATCH /licenses/:id/extend
    • GET /analytics/stats

About

Official Unity SDK for LicenseChain — license validation and management

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages