PHP code example of keboola / api-bundle
1. Go to this page and download the library: Download keboola/api-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
keboola / api-bundle example snippets
use Keboola\ApiBundle\Attribute\StorageApiTokenAuth;
use Keboola\ApiBundle\Security\StorageApiToken\SecurityApiToken;
use Symfony\Component\Security\Http\Attribute\CurrentUser;
#[StorageApiTokenAuth]
class Controller {
public function __invoke(#[CurrentUser] StorageApiToken $token)
{
// only requests with valid X-StorageApi-Token will be allowed
}
}
#[StorageApiTokenAuth(features: ['feat-a', 'feat-b'])]
class Controller {
public function __invoke(#[CurrentUser] StorageApiToken $token)
{
// only requests with valid X-StorageApi-Token and project features 'feat-a' AND 'feat-b' is allowed
}
}
#[StorageApiTokenAuth(features: ['feat-a'])]
#[StorageApiTokenAuth(features: ['feat-b'])]
class Controller {
public function __invoke(#[CurrentUser] StorageApiToken $token)
{
// only requests with valid X-StorageApi-Token and any of project features 'feat-a' OR 'feat-b' ise allowed
}
}
#[ManageApiTokenAuth(scopes: ['something:manage'])]
#[StorageApiTokenAuth]
class Controller {
public function __invoke(
string $entityId,
#[CurrentUser] TokenInterface $token,
) {
// allows request with either valid X-KBC-ManageApiToken with 'something:manage' scope OR any valid X-StorageApi-Token
// but with additional checks in controller
$entity = $this->fetchEntity($entityId);
if ($token instanceof StorageApiToken && $token->getProjectId() !== $entity->getProjectId()) {
throw new AccessDeniedHttpException('...');
}
}
}