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.

circle-exclamation

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( 
    sharinpix.SharinPixPermission.mergeAlbumAbilities( 
      recordId, 
      'SharinPixPermissionName', 
      new Map<String, Object> {
          'Id' => recordId
        }
     )
  );
  return token;
}
circle-exclamation

mergeAlbumAbilities

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.

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.

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

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

Last updated

Was this helpful?