strong-license
Simple license generator/validator using JWT with the pre-defined claim names (fields) and validation semantics.
product
- a string identifying the product the license applies tofeatures
- an array of strings identifying features of the productactivationDate
- a Date indicating when the license period startsexpirationDate
- a Date indicating when the license period endsemail
- a string identifing who the license is for (primarily used for logging and identification for support purposes)
Both the product
and features
fields support *
as a wildcard to indicate
that all products or features are covered by the license. When the product
field is a wildcard, any product check matches but it does not imply that all
features are covered. When the features list contains a wildcard as one of its
entries, any feature check matches.
Usage
The strong-license module defines the License class, which can be used for generating, parsing, and validating a license key.
Generating a License Key
var License = License;var details = email: 'user@example.com' product: 'enterprise-node' features: 'foo' 'bar' 'baz' activationDate: expirationDate: Date + 1000*60*60*24*365;var lic = details 'super secret key!'; processenvLICENSE_KEY = lickey;
It is also possible to generate a null license, which does not cover any products or features and is perpetually expired. It does, however, cover the null query scenario.
var License = License;var nullLicense = ; nullLicense; // => true! Can't do anything, but can do nothing!
Parsing/Validating a License Key
If a license coverage query omits a field, that field is considered a match.
var License = License;var now = ;var yesterday = Date - 1000*60*60*24;var lic = processenvLICENSE_KEY 'super secret key!'; lic; // => truelic; // => false
If a parameter is omitted, is considered a match.
lic; // => truelic; // => truelic; // => falselic; // => true! any license covers "nothing"