It's common to have apps that need to work even without an internet connection. Keyforge makes it easy to validate licenses oflline.
An internet connection is only required to activate the license and to
occasionally refresh the license token.
To make this possible, Keyforge can issue a signed license token that can be verified on the client. The token is a JWT and contains information about the license.
Go to license tokens and add a new product. You can edit how much time a token will be valid for, and other options after creating the new configuration.
For setups with more than one product, you can duplicate the signing key pair
from another product inside the edit menu. You can also import an external
key pair.
The SDK provides a simple way to validate and automatically refresh license tokens. You should call validateAndRefreshToken when your app starts.
import { validateAndRefreshToken } from '@keyforge/client/token';const PUBLIC_KEY = '...'; // Copied from the dashboard. In JSON string or object formatconst { isValid, token, data, isValidButExpired } = await validateAndRefreshToken({ token: getStoredToken(), // The current license token publicKeyJwk: PUBLIC_KEY, deviceIdentifier: 'some_device_id', productId: 'p_123456', });if (isValid) { storeToken(token); // Store the new token if it was refreshed console.log('License token is valid!', data.license.key);} else if (!isValidButExpired) { // A network error probably occurred. The token is expired, but was valid // You should NOT prompt the user to activate a license}// If the token is not valid, you should prompt the user to activate a license