--- title: Generate a custom platform token for the Hosted Insight Panel component slug: n81d0055 canonical_url: https://docs.coveo.com/en/n81d0055/ collection: coveo-for-salesforce source_format: adoc --- # Generate a custom platform token for the Hosted Insight Panel component > **Available since** > > This feature was introduced in the August 2023 release of Coveo for Salesforce version [5.2](https://docs.coveo.com/en/n5bj0150#august-2023-release-v5-2-initial-release). Platform tokens are special [JSON web tokens](https://jwt.io/) that can be used to [query](https://docs.coveo.com/en/231/) almost any Coveo API as a specific [user](https://docs.coveo.com/en/250/). To add custom data such as additional identities to a platform token, you must generate a _custom_ platform token. > **Note** > > Currently, the Search API [doesn't support platform token authentication](https://docs.coveo.com/en/102/). To generate a custom platform token . [Create an Apex class](https://help.salesforce.com/s/articleView?id=sf.code_manage_packages.htm&type=5). . In the new Apex class, enter the following template: ```apex global with sharing class implements CoveoV2.InsightTokenGeneratorInterface { public String generateInsightToken(Map param) { String token = ''; Map platformTokenParams = new Map(); // Add required privileges for Hosted Insight Panel List tokenPrivileges; String[] userActionIds = CoveoV2.Globals.getUserActionIds(recordId, new List{ 'CreatedBy.Email' }); if (userActionIds.size() > 0) { String userActionTarget = userActionIds[0]; Map tokenPrivilegesParams = new Map{ 'userActionTarget' => userActionTarget }; tokenPrivileges = CoveoV2.PlatformToken.buildInsightTokenPrivileges(tokenPrivilegesParams); } else { tokenPrivileges = CoveoV2.PlatformToken.buildInsightTokenPrivileges(); } platformTokenParams.put('privileges', tokenPrivileges); // Add additional user identities List additionalIdentities = new List{ new CoveoV2.UserIdentity('john@doe.com'), new CoveoV2.UserIdentity('john@doe.com', 'Email Security Provider'), new CoveoV2.UserIdentity('john@doe.com', 'Email Security Provider', 'User') }; CoveoV2.PlatformToken.SearchTokenOptions searchTokenOptions = new CoveoV2.PlatformToken.SearchTokenOptions(); searchTokenOptions.userIds.addAll(additionalIdentities); platformTokenParams.put('search', searchTokenOptions); token = CoveoV2.Globals.generatePlatformToken(platformTokenParams); return token; } } ``` Where you replace `` with the name you chose for your new Apex class. > **Important** > > The Apex class must be `global`. > Otherwise, it won't appear as an option in the **Coveo Hosted Insight Panel** component's [**Token Generator**](https://docs.coveo.com/en/m7ed8015#tokengenerator) picklist. > **Tip** > > For information on specifying additional user identities, see the Globals class [reference documentation](https://docs.coveo.com/en/1075#additionaluseridentity-optional). . 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](https://docs.coveo.com/en/m7ed8015#tokengenerator) to override the default platform token for your Hosted Insight Panel configuration.