keboola / api-bundle
Keboola API Bundle
Requires
- php: >=8.1
- cuyz/valinor-bundle: ^0.2.3
- keboola/permission-checker: ^2.0
- keboola/service-client: ^1.0
- monolog/monolog: ^2.0
- symfony/dependency-injection: ^6.0
- symfony/monolog-bundle: ^3.8
- symfony/security-bundle: ^6.1
Requires (Dev)
- keboola/api-error-control: ^4.1
- keboola/coding-standard: ^15.0
- keboola/kbc-manage-api-php-client: ^7.0
- keboola/storage-api-php-client-branch-wrapper: ^5.1
- phpstan/phpstan: ^1.8
- phpstan/phpstan-phpunit: ^1.1
- phpstan/phpstan-symfony: ^1.3
- phpunit/phpunit: ^9.5
- sempro/phpunit-pretty-print: ^1.4
- symfony/framework-bundle: ^6.1
- symfony/yaml: ^6.1
- dev-main
- 3.5.0
- 3.4.0
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.0
- 2.0.0
- 1.0.1
- 1.0.0
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.0
- 0.0.1
- dev-erik-PST-2051
- dev-pepa_PST-777_tableIngoGenerator
- dev-odin-PST-1670
- dev-pepa_k8s_deployment
- dev-roman-pst-1710
- dev-pepa_auth_adminToken
- dev-rrik-om-ci-fixup
- dev-erik-PST-850-part2
- dev-erik-GCP-374-part3
- dev-erik-GCP-472
- dev-erik-GCP-374-part1
- dev-odin-GCP-374-c
This package is auto-updated.
Last update: 2024-09-20 10:12:31 UTC
README
Symfony 扩展包,为 Keboola API 应用程序提供常用功能。
安装
使用 Composer 安装此包
composer require keboola/api-bundle
配置
该扩展包期望在您的 Symfony 配置中定义 %app_name%
参数。
默认配置
keboola_api: app_name: '%app_name%' # application name to use in user agent default_service_dns_type: public # default service DNS type to use in ServiceClient, can be 'public' or 'private'
功能
预配置的 ServiceClient
该扩展包提供预配置的 ServiceClient
,可用于解析 Keboola API URL。默认情况下,它配置为使用公共主机名,但可以重新配置为使用内部主机名。
keboola_api: default_service_dns_type: internal
使用 ENV 变量
如果您需要使用 ENV 变量来配置 default_service_dns_type
,请确保您提供一些默认值,否则验证将失败,错误信息为:The value "" is not allowed for path "keboola_api.default_service_dns_type".
parameters: env(API_DNS_TYPE): internal keboola_api: default_service_dns_type: '%env(API_DNS_TYPE)%'
使用属性进行控制器认证
要使用属性认证,请配置防火墙使用 keboola.api_bundle.security.attribute_authenticator
security: firewalls: attribute: lazy: true stateless: true custom_authenticators: - keboola.api_bundle.security.attribute_authenticator
然后向您的控制器添加任何组合的认证属性
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('...'); } } }
要使用单个认证属性,您需要安装适当的客户端包
- 要使用
StorageApiTokenAuth
,请安装keboola/storage-api-client
- 要使用
ManageApiTokenAuth
,请安装keboola/kbc-manage-api-php-client
注意
如果您忘记安装适当的客户端,您将获得类似以下的异常:Service "Keboola\ApiBundle\Attribute\ManageApiTokenAuth" not found: the container inside "Symfony\Component\DependencyInjection\Argument\ServiceLocator" is a smaller service locator
许可证
MIT 许可,请参阅 LICENSE 文件。