Generate a custom platform token for the Hosted Insight Panel component

In this article

Platform tokens are special JSON web tokens that can be used to query almost any Coveo API as a specific user. To add custom data such as additional identities to a platform token, you must generate a custom platform token.


To generate a custom platform token

  1. Create an Apex class.

  2. In the new Apex class, enter the following template:

    global with sharing class <MY_APEX_CLASS> implements CoveoV2.InsightTokenGeneratorInterface {
        public String generateInsightToken(Map<String, Object> param) {
            String token = '';
            Map<String, Object> platformTokenParams = new Map<String, Object>();
            // Add required privileges for Hosted Insight Panel
            List<CoveoV2.PlatformToken.TokenPrivilege> tokenPrivileges = CoveoV2.PlatformToken.buildInsightTokenPrivileges();
            platformTokenParams.put('privileges', tokenPrivileges);
            // Add additional user identities
            List<CoveoV2.UserIdentity> additionalIdentities = new List<CoveoV2.UserIdentity>{
                new CoveoV2.UserIdentity(''),
                new CoveoV2.UserIdentity('', 'Email Security Provider'),
                new CoveoV2.UserIdentity('', 'Email Security Provider', 'User')
            CoveoV2.PlatformToken.SearchTokenOptions searchTokenOptions = new CoveoV2.PlatformToken.SearchTokenOptions();
            platformTokenParams.put('search', searchTokenOptions);
            token = CoveoV2.Globals.generatePlatformToken(platformTokenParams);
            return token;

    Where you replace <MY_APEX_CLASS> with the name you chose for your new Apex class.


    The Apex class must be global. Otherwise, it won’t appear as an option in the Coveo Hosted Insight Panel component’s Token Generator picklist.


    For information on specifying additional user identities, see the Globals class reference documentation.

  3. Save the Apex class.

What’s next

Once you have an Apex class that implements the CoveoV2.InsightTokenGeneratorInterface, you’ll see it appear as an option in the Coveo Hosted Insight Panel component’s Token Generator picklist. You can now select your new Apex class to override the default platform token for your Hosted Insight Panel configuration.