6

We've developed a Kentico module that we would like to license on a per site basis.

Has anyone else tried to leverage the in-built Kentico Licensing for this purpose?

What I'm thinking of is having a secure end-point on our server that would validate the domain/license of the Kentico site running the module.

E.g. If the domain/license does not exist in our servers the module won't run for the site.

Is this feasible?

rocky
  • 7,506
  • 3
  • 33
  • 48
Pedro Costa
  • 2,968
  • 2
  • 18
  • 30

1 Answers1

4

I think I may have figured this one out.

On my module I've overriden the CheckLicense method as such:

    public override bool CheckLicense(string domain, FeatureEnum feature, ObjectActionEnum action)
    {
        if (domain != null)
            domain = LicenseKeyInfoProvider.ParseDomainName(domain);

        int siteId = LicenseHelper.GetSiteIDbyDomain(domain);
        var licenseKey = LicenseKeyInfoProvider.GetLicenseKeyInfo(domain, FeatureEnum.Unknown);
        if (siteId > 0 && licenseKey != null)
        {
            // TODO: query external service with licenseKey.Domain for a valid license for this module
            return true;
        }

        return false;
    }

And then I can use:

ModuleManager.CheckModuleLicense("My.Module.Name", RequestContext.CurrentDomain, FeatureEnum.Unknown, ObjectActionEnum.Read)

On the features to ensure the module is properly licensed.

The method override is a simplification, I've implemented caching on the external services requests, to prevent having to query the service every time we want to check for permissions.

I'm also sending the licenseKey.Domain because we don't care about aliases, as long as the main domain is licensed the module should work under any aliases.

How does this approach looks? Would really appreciate any feedback from anyone that has done something of the sort, and what was the opted for solution?

Thanks, p.

Pedro Costa
  • 2,968
  • 2
  • 18
  • 30
  • You can use `SiteDomainAliasInfoProvider` to get all aliases of a site...is that what you're looking for? – rocky Nov 26 '15 at 09:13
  • Actually quite the oposite, im looking for the domain of the main license issued by Kentico, regardless of alias or test/development licenses. – Pedro Costa Nov 26 '15 at 14:45
  • And what information do you have available? I think that by combining `SiteInfoProvider`, `SiteDomainAliasInfoProvider` and `LicenseKeyInfoProvider` you should be able to retrieve the information regardless of whether you have site id, domain name, or domain alias available. – rocky Nov 26 '15 at 15:17
  • SiteDomainAliasInfoProvider does not give much, an since I'm only keen on validating the main license I ended up going very much with the solution in the code of my answer. hopefully some one from #Kentico could confirm it's usage? – Pedro Costa Dec 11 '15 at 16:47