Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leverage Kentico's Licensing to license custom module

Tags:

c#

kentico

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?

like image 493
Pedro Costa Avatar asked Nov 25 '15 17:11

Pedro Costa


1 Answers

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.

like image 193
Pedro Costa Avatar answered Sep 20 '22 01:09

Pedro Costa