Skip to content

Consuming licenses using identity-based licensing

Once the SDK has been initialized from configuration and the user has been authenticated or identified via some means and the application is in possession of either an IdToken or combination of a ScaleJWT and license consumer id are known, the application can consume licenses by identity based licensing.

The application can now initialize a license checkout client. Depending on whether the application is using enforced or metered licensing, this will either be an EnforcedLicenseCheckoutClient or a MeteredLicenseCheckoutClient.

To initialize the client, pass the licensing API URL and the authorized session to the client:

from tenduke_core.auth import PkceFlowClient
from tenduke_core.auth.oidc_discovery import load_openid_config
from tenduke_core.config import TendukeConfig

from tenduke_scale.http import ScaleSessionFactory
from tenduke_scale.license_checkout import EnforcedLicenseCheckoutClient

# OAuth/OIDC configuration would also be required, see authentication samples
config = TendukeConfig.load(
    idp_oidc_discovery_url="https://idp.example.com/user/.well-known/openid-configuration",
    licensing_api_url="https://example-baseurl.lic-api.scale.10duke.com",
)
session_factory = ScaleSessionFactory(config, "license-checkout-client-id-licensing-example", "1.0.0")
load_openid_config(session_factory, config)
login_client = PkceFlowClient(config, session_factory)

login_client.login_with_default_browser()

session_factory = ScaleSessionFactory(
    config,
    "license-checkout-client-identity-licensing-example",
    "1.0.0",
)

session = session_factory.create(auth=login_client.auth())

checkout_client = EnforcedLicenseCheckoutClient(config.licensing_api_url, session)

The LicenseCheckoutClientABC provides methods to query for and checkout licenses.

A typical flow would involve checking out a license, checking the options the license enables in the application, periodically calling heartbeat to check the license is still valid, and releasing the license.

For identity-based licensing, this will also require knowledge of the licensee from whom licenses will be consumed.

You can get a list of the licensees that a license consumer is connected to using the LicenseCheckoutClientABC.describe_licensees method.

The application would then prompt the user to select the licensee that they want to consume licenses from (or move on the next step if there is only one licensee returned).

The application may know exactly which licenses are required, or some may be optional. In either case, the application would need to obtain the list of licenses available to the user from the licensee.

This can be achieved using the LicenseCheckoutClientABC.describe_licenses method.

The application can then either select the licenses from the response or display them for the user to choose from.

Once a selection has been established, the application would check out the license(s) or start metered license use.

The retrieved LicenseToken objects will be stored in the configured TokenStoreABC.

The LicenseToken objects should be used to call the Heartbeat API at a regular cadence, to ensure the licenses are still valid and the user still has access to them.

The license can be released (either when the user indicates they want to switch licenses, when the application is shutdown, or some other trigger based on your requirements) or the metered use ended.