Access token for image upload
About
The upload access token can be used for authenticating the API image upload. Unlikely the API credentials, the access token can be created only through the Shardimage API and it can be limited in time and usage. Some features, like the Shardimage upload widget accepts only upload access token authentication, if Shardimage is the upload destination.
Example
use shardimage\shardimagephp\auth\Client;
use shardimage\shardimagephp\models\accesstoken\UploadAccessToken;
use shardimage\shardimagephp\models\accesstoken\UploadAccessTokenExtra;
$client = new Client([
'apiKey' => '<apiKey>',
'apiSecret' => '<apiSecret>',
'imageSecret' => '<imageSecret>',
'cloudId' => '<cloudId>',
]);
$token = new UploadAccessToken();
$token->expiry = time() + 3600; // Access token can be used for 1 hour
$token->limit = 1000; // Access token can be used 1000 times
$token->extra = new UploadAccessTokenExtra([
'cloudId' => '<cloudId>', // Restricted to one cloud
'notificationUrls' => [ // Send notification to the given URLs
'<url>'
],
'tags' => [ // Set up deafult image tags
'<tag1>',
'<tag2>',
],
]);
$response = $client->getAccessTokenService()->create($token);
if ($response instanceof UploadAccessToken) {
echo $response->id; // Token is ready to be used
} else {
// Detect and handle error
}