Validate license

You can validate a license using the SDK. Here we are checking if the license is valid for a certain device and product ID. In this example, the device with identifier some_device_id, and the product ID p_123456.

import { Keyforge } from 'keyforge-js';
 
const keyforge = new Keyforge('sk_1234');
 
const validation = await keyforge.licenses.validate(
  'ABCDE-ABCDE-ABCDE-ABCDE-ABCDE',
  {
    deviceIdentifier: 'some_device_id',
    productId: 'p_123456',
  }
);

It is recommended to only validate a license using a device identifier and a product ID, as it provides more security. However, both parameters are optional.

Parameters

PropTypeDefault
key
string
-
params
ValidateLicenseParams | undefined
-

ValidateLicenseParams type

PropTypeDefault
deviceIdentifier
string | undefined
-
productId
string | undefined
-

Returns

Here is an example of the returned validation object:

A license can have the status active and still not be valid. For example, if you validate for a certain device and product ID, and the license is not valid for that device or product ID.

{
  "isValid": true,
  "status": "active",
  "device": {
    "identifier": "some_device_id",
    "name": "My computer name",
    "activationDate": "2024-05-19T18:39:33.000Z"
  },
  "license": {
    "key": "ABCDE-ABCDE-ABCDE-ABCDE-ABCDE",
    "userId": "05d27bfb-61c7-45f7-9d07-09a41defc88a",
    "productId": "p_123456",
    "type": "perpetual",
    "expiresAt": null,
    "revoked": false,
    "email": "[email protected]",
    "maxDevices": 2,
    "activeDevices": [
      {
        "identifier": "some_device_id",
        "name": "My computer name",
        "activationDate": "2024-05-19T18:39:33.000Z"
      }
    ],
    "createdAt": "2024-05-19T18:39:33.000Z"
  }
}