Generate token from SharinPix Permission with Apex

In this article, you will learn how to generate a token for the SharinPix Album component from a SharinPix Permission.

The article also demos how to extend the album's permissions/abilities using code.

Create a SharinPix Permission record to be used to generate the token.


If you want to remove or add any permission to your album, you will simply need to modify the SharinPix Permission record on Salesforce, no need to modify the corresponding code. 

Generating token

The code snippet below demonstrates how to generate a SharinPix online token in an Apex method:

public String generateToken(String recordId) {
  sharinpix.Client clientInstance = sharinpix.Client.getInstance();
  String token = clientInstance.token( 
      new Map<String, Object> {
          'Id' => recordId
  return token;


  • The SharinPixPermissionName highlighted above should be replaced with the name of the SharinPix Permission you created before.
  • mergeAlbumAbilities highlighted above is a global method. Below is a more detailed description of the method.


global static Map<String, Object> mergeAlbumAbilities(String albumId, String permissionNameOrId, Map<String, Object> options)

The mergeAlbumAbilities method is used to create a map of permissions using a SharinPix Permission, and extending the abilities by adding other permissions on top of the SharinPix Permission.

Map<String, Object> permission = 
        new Map<String, Object> {'exp' => 0}

Click to copy

Get token Parameter inside Lightning Component

  • The sample code below shows how the token value is used to display the SharinPix Album inside the markup of a Lightning Component.
<aura:component controller="ClassName"
implements="force:hasRecordId,flexipage:availableForAllPageTypes >
    <aura:attribute name="recordId" type="String"/>
    <aura:attribute name="token" type="String"/>

    <aura:handler name="init" value="{! this }" action="{! c.doInit }"/>

    <iframe src="{! v.token }" width="100%" height="500px"></iframe>

ClassName highlighted above should be replaced with the name of your apex class, where you have the generateToken method.

    doInit : function(component) {
        var recordId = component.get("v.recordId");
        var action = component.get("c.generateToken");           
        action.setParams({ recordId: recordId });          
        action.setCallback(this, function(response) {       
            if (response.getState() === "SUCCESS") {
                + response.getReturnValue());
            } else if (response.getState() === "ERROR"){ 

The method generateToken is the apex method shown below, it should be @AuraEnabled to be able to access it in the aura component. 

public class className {    
    public static String generateToken(String recordId) { 
        sharinpix.Client clientInstance = sharinpix.Client.getInstance();        
        String token = clientInstance.token(
                new Map<String, Object> {
                    'Id' => recordId
        return token;


Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.