SDKs
...
Getting Started
C++
C++ SDK Configuration and Usage
13min
c++ sdk allows implementing licensing in two ways \ using the license and licensemanager classes; \ using the licensehandler class licensehandler encapsulates license and licensemanager functionality by default, it is exceptions free, but you can enable exceptions it's up to you whether to use licensemanager and license directly or use this class licensehandler is also useful for unreal engine clients because it is free of memory access violation problems due to runtime conflicts with ue this article has code samples for both approaches in the other ones, we will demonstrate sdk usage only with licensemanager and license licensehandler class has methods corresponding to license / licensemanager functionality see also our error handling docid 0tnmm6shdrcmlpx4tuoo tutorial configuration to initialize the sdk you will need to fill in your application name and version, product code, and licensespring authentication credentials api and shared key, or oauth client id and client secret oauth support was added in v7 35 0 of the sdk see oauth authorization docid\ xhyzaual9qy4jerxkilmk on how to set up oauth all credentials can be found can be found on your licensespring account under settings >keys api and shared key location your product code is located in your product list under configure products product coproduct code location location please, keep in mind that the product code field is case sensitive when you have the necessary values, create the configuration std string appname = "my licensespring application"; std string appversion = "1 0 0"; // use in case of standard authentication std string apikey = "xxxxxxxx xxxx xxxx xxxx xxxxxxxxxxxx"; std string sharedkey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // use in case of oauth authentication std string clientid = "xxxxxx xxxxx yyy"; std string clientsecret = "ssssssssssssssssssssssssssssss"; std string productcode = "xx"; auto configuration = licensespring configuration create( apikey, sharedkey, productcode, appname, appversion ); // or // setting cryptoprovider key is necessary when using oauth // configuration >getcryptoprovider >setkey("password for license encryption key generation"); // auto configuration = licensespring configuration createoauth( clientid, clientsecret, productcode, appname, appversion ); now you can initialize licensemanager or licensehandler using this configuration object licensemanager auto licensemanager = licensemanager create( configuration ); licensehandler auto& licensehandler = licensehandler instance(); licensehandler reconfigure( configuration ); license activation the license keys are located in licenses section license key location to implement user based licensing please refer to user based licensing docid\ xepx04m3oh f6s8ylf6mz to activate a license, create a licenseid using the given key and call activation method licensemanager auto licenseid = licenseid fromkey( "xxxx xxxx xxxx xxxx" ); auto license = licensemanager >activatelicense( licenseid ); licensehandler auto& licensehandler = licensehandler instance(); auto licenseid = licenseid fromkey( "xxxx xxxx xxxx xxxx" ); licensehandler activatelicense( licenseid ); the process of activating a license refers to binding a device to a license on the licensespring platform, activating the license increments the total activations counter within the license ssoexception with the message "customer account code is not set " can occur due to incorrect use of the activatelicense function this function has two overloads for a regular license activation, it takes only licenseid the overload that takes strings is used for sso for more information, see single sign on docid\ fwgt 4dz4ziewel1nosxq local license the local license is a copy of the license information that is saved on the end user's local computer users who have not activated the license on their end before will not have a local license by default, the local license is stored %userprofile%\appdata\local\licensespring\”product code”\license key see local license file docid\ fkfzhha n838tznrzu0sz for more information if a device already has a license, and you try to activate another license on that device, for the same product, that newly activated license will override the existing license, deleting it from the device this will be on the developer to make sure that they check if a license exists on the device before a new activation licensemanager auto license = licensemanager >getcurrentlicense(); if( license == nullptr ) //activate a new license licensehandler auto& licensehandler = licensehandler instance(); if( !licensehandler islicenseexists() ) //activate a new license license check it is recommended to perform a local license check at application start to confirm that the local license file belongs to the current device and has not been transferred it is also useful to check whether the local license file has been tampered with and whether the local license is still valid an additional check verifies the license signature returned by the license api on license activation or check if the license was tampered with, the local check will throw an exception if the verifysignature parameter is set to true if the license was activated with c++ sdk v7 32 0 or earlier, local check with signature verification will throw an exception because the local license state doesn't contain the signature signed by the licensespring backend in that case, users must first either do an offline license update, or an online license check this only needs to be done once license bool verifysignature = false; // also false by default license >localcheck( verifysignature ); //throws exceptions in case of errors licensehandler auto& licensehandler = licensehandler instance(); licensehandler checklicenselocal(); if( licensehandler waserror() ) //handle errors lserrorcode error = lh getlasterror(); else //license check is successful the local check can produce the following errors exception error code reason licensestateexception elicensedisabled elicenseinactive elicenseexpired license is in invalid state (disabled, epired or inactive) productmismatchexception eproductmismatcherror license does not belong to configured product devicenotlicensedexception edeviceerror license does not belong to current device clocktamperedexception eclocktamperederror detected cheating with system clock floatingtimeoutexpiredexception efloatingtimeoutexpired timeout for floating license has expired vmisnotallowedexception evmnotallowed vm was detected while vm check is turned on signaturemismatchexception esignaturemismatcherror local license signature has been tampered with online license check refreshes the local license with the data from licensespring backend license license >check(); //throws exceptions in case of errors licensehandler auto& licensehandler = licensehandler instance(); licensehandler checklicense(); if( licensehandler waserror() ) //handle errors lserrorcode error = lh getlasterror(); else //license check is successful the online check can produce the following errors exception error code reason licensestateexception elicensedisabled elicenseinactive elicenseexpired license is disabled, was reset or expired devicenotlicensedexception deviceblacklistedexception edeviceerror edeviceblacklisted license does not belong to current device or the device was blacklisted nointernetexception networktimeoutexception licenseserverexception enointerneterror enetworktimeouterror eservererror connection related errors if there's no internet or an internal server error occured maxfloatingreachedexception emaxfloatingreached there are no free floating slots for license unknownlicensespringexception eunknownerror unknown error contact support in this case oauthexception eunauthorizedclient eoauthrequired eoauthtokenexpired invalid client credentials license requires oauth authentication oauth token is expired this shouldn't happen as the sdk keeps track of its lifetime this method also returns the most recent installationfile available for the license which can be useful for managing software updates for more information about managing software updates, see handling product versions docid\ zvfcf4 5cq4uj4dnsovbb you can also check for active, valid, enabled, and expired licenses using isactive , isvalid , isenabled , and isexpired methods respectively note that an active license does not necessarily mean a license is valid a valid license means the license is active, enabled, and not expired an active license means that the license is bound to a device, but may also be disabled or expired full code sample below you can find a code sample that initializes the sdk, retrieves a local license or activates a new one, and performs the necessary checks licensemanager std string appname = "my licensespring application"; std string appversion = "1 0 0"; // use in case of standard authentication std string apikey = "xxxxxxxx xxxx xxxx xxxx xxxxxxxxxxxx"; std string sharedkey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // use in calse of oauth authentication std string clientid = "xxxxxx xxxxx yyy"; std string clientsecret = "ssssssssssssssssssssssssssssss"; std string productcode = "xx"; auto configuration = licensespring configuration create( apikey, sharedkey, productcode, appname, appversion ); // or // setting cryptoprovider key is necessary when using oauth // configuration >getcryptoprovider >setkey("password for license encryption key generation"); // auto configuration = licensespring configuration createoauth( clientid, clientsecret, productcode, appname, appversion ); try { auto licensemanager = licensemanager create( configuration ); auto license = licensemanager >getcurrentlicense(); if( license == nullptr ) { auto licenseid = licenseid fromkey( "xxxx xxxx xxxx xxxx" ); license = licensemanager >activatelicense( licenseid ); } license >localcheck(); license >check(); } catch( const licensespringexception& ex ) { std cout << "licensespring exception encountered " << ex what(); } licensehandler std string appname = "my licensespring application"; std string appversion = "1 0 0"; std string apikey = "xxxxxxxx xxxx xxxx xxxx xxxxxxxxxxxx"; std string sharedkey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; std string productcode = "xx"; auto configuration = licensespring configuration create( apikey, sharedkey, productcode, appname, appversion ); auto& licensehandler = licensehandler instance(); licensehandler reconfigure( configuration ); if( !licensehandler islicenseexists() ) { auto licenseid = licenseid fromkey( "xxxx xxxx xxxx xxxx" ); licensehandler activatelicense( licenseid ); if( licensehandler waserror() ) std cout << "licensespring error encountered " << licensehandler getlasterrormsg(); } licensehandler checklicenselocal(); if( licensehandler waserror() ) std cout << "licensespring error encountered " << licensehandler getlasterrormsg(); licensehandler checklicense(); if( licensehandler waserror() ) std cout << "licensespring error encountered " << licensehandler getlasterrormsg(); license deactivation deactivating a license unbinds the device from the license, and decrements the number of total activations depending on the license transfer policy, this usually means that the license is freed up to be activated onto a new device deactivating is done using the following method license if( license >deactivate() ) std cout << "license deactivated successfully "; licensehandler auto& licensehandler = licensehandler instance(); if( licensehandler deactivatelicense() ) std cout << "license deactivated successfully "; the license deactivate() method allows to specify whether you want to remove the local license file after the deactivation set the removelocaldata parameter to true if you want the local files to be removed