> For the complete documentation index, see [llms.txt](https://docs.licensespring.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.licensespring.com/sdks/go-sdk/v2/samples/online-licenses.md).

# 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.

{% stepper %}
{% step %}

### Initialize the License Handler

To begin working with an online license, you must initialize a `LicenseHandler` using your product and license credentials.

{% tabs %}
{% tab title="Without OAuth" %}

```go
	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)
```

{% endtab %}

{% tab title="With OAuth" %}
When using OAuth, you must provide a `CryptoProviderKey`, which is required to securely encrypt and decrypt the license data.

```go
	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)
```

{% endtab %}

{% tab title="With Hardware Key" %}
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.

```go
lh, err := SetupLicenseHandlerWithHWKey(useOAuth, pin, productCode)
if err != nil {
    fmt.Println("license handler setup error:  \n", err)
    return err
}
```

{% endtab %}
{% endtabs %}

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.
{% endstep %}

{% step %}

### Activate the License

Once the license handler is configured, activate the license:

```go
	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.
{% endstep %}

{% step %}

### Check the License

After activation, you can verify the license status at any time:

```go
	ld, err = lh.CheckLicense(ctx)
	if err != nil {
		return err
	}
```

This communicates with the API to ensure the license is still valid and up-to-date.
{% endstep %}

{% step %}

### Deactivate the License

To deactivate the license when no longer needed:

```go
	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.
{% endstep %}

{% step %}

### Resume from Local License File

If your application restarts and you haven't removed the local license file, you can resume the license state from disk:

```go
	ld, err = lh.GetCurrentLicense()
	if err != nil {
		return err
	}
```

{% endstep %}
{% endstepper %}

{% hint style="info" %}

* Online licenses require internet connectivity at the time of activation and checks.
* Local license data can be reused as long as it hasn’t been removed or expired.
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.licensespring.com/sdks/go-sdk/v2/samples/online-licenses.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
