Online Licenses
The SDK provides support for online license activation, check, and deactivation. This flow requires internet access and communicates directly with the LicenseSpring API.
Initialize the License Handler
To begin working with an online license, you must initialize a LicenseHandler using your product and license credentials.
c := license_handler.LicenseHandlerConfig{
ApiKey: "your api key",
SharedKey: "your shared key",
ProductCode: "your product code",
AuthData: auth.FromKey("your license key"),
OAuth: false,
}
lh, err := license_handler.NewLicenseHandler(c)When using OAuth, you must provide a CryptoProviderKey, which is required to securely encrypt and decrypt the license data.
c := license_handler.LicenseHandlerConfig{
ClientId: "your client ID",
ClientSecret: "your client secret",
CryptoProviderKey: "your crypto key",
ProductCode: "your product code",
AuthData: auth.FromKey("your license key"),
OAuth: false,
}
lh, err := license_handler.NewLicenseHandler(c)If you are using the default PIN, enter "123456" as the argument. The configuration is loaded from a file but can be adjusted based on your own setup or environment. The rest of the flow remains identical to the standard online license examples above.
By default, this setup uses the SDK’s file-based storage, meaning license data is persisted to a local file. You can customize the storage method if needed, but all examples in this guide assume file storage.
Activate the License
Once the license handler is configured, activate the license:
ctx := context.Background()
var ld *types.LicenseData
ld, err = lh.ActivateLicense(ctx)
if err != nil {
return err
}This will send an activation request to the LicenseSpring API. If successful, the SDK stores the license locally for future use.
Deactivate the License
To deactivate the license when no longer needed:
removeLocalData := true
ld, err = lh.DeactivateLicense(ctx, removeLocalData)
if err != nil {
return err
}Setting removeLocalData to true will delete the local license file. If set to false, the file remains and can be reused later.
Last updated
Was this helpful?