Leverage Kentico's Licensing to license custom module
Asked Answered
M

1

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?

Mantelet answered 25/11, 2015 at 17:15 Comment(0)
M
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.

Mantelet answered 25/11, 2015 at 19:32 Comment(4)
You can use SiteDomainAliasInfoProvider to get all aliases of a site...is that what you're looking for?Micky
Actually quite the oposite, im looking for the domain of the main license issued by Kentico, regardless of alias or test/development licenses.Mantelet
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.Micky
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?Mantelet

© 2022 - 2024 — McMap. All rights reserved.