tourze / access-key-bundle
Installs: 9
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/access-key-bundle
Requires
- doctrine/data-fixtures: ^2.0
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/doctrine-fixtures-bundle: ^4.0
- doctrine/orm: ^3.0
- doctrine/persistence: ^4.1
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- symfony/config: ^7.3
- symfony/console: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/event-dispatcher: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/http-foundation: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/security-core: ^7.3
- symfony/security-http: ^7.3
- symfony/service-contracts: ^3.6
- symfony/yaml: ^7.3
- tourze/bundle-dependency: 1.*
- tourze/doctrine-indexed-bundle: 1.0.*
- tourze/doctrine-snowflake-bundle: 1.0.*
- tourze/doctrine-timestamp-bundle: 1.0.*
- tourze/doctrine-track-bundle: 1.0.*
- tourze/doctrine-user-bundle: 1.0.*
- tourze/easy-admin-menu-bundle: 1.0.*
- tourze/symfony-dependency-service-loader: 1.0.*
Requires (Dev)
This package is auto-updated.
Last update: 2025-11-02 06:04:39 UTC
README
Symfony Bundle for API access key management with signature verification, IP whitelist, and AES encryption support.
Features
- Access Key Management: AppID/AppSecret key pair management
- Signature Verification: Configurable signature timeout (default 180 seconds)
- IP Whitelist: Restrict access to specific IPs
- AES Encryption: Support for AES key configuration
- Statistics: Success/failure call statistics
- EasyAdmin Integration: Admin panel interface
- Access Control: Requires ROLE_ADMIN permission
Installation
composer require tourze/access-key-bundle
Configuration
Register in config/bundles.php:
return [ // ... Tourze\AccessKeyBundle\AccessKeyBundle::class => ['all' => true], ];
Run database migrations:
php bin/console doctrine:migrations:migrate
Usage
1. Get Valid Access Key
use Tourze\AccessKeyBundle\Service\ApiCallerService; class YourController { public function __construct( private ApiCallerService $apiCallerService ) {} public function someAction(Request $request): Response { $appId = $request->headers->get('X-App-Id'); $accessKey = $this->apiCallerService->findValidApiCallerByAppId($appId); if (!$accessKey) { throw new UnauthorizedHttpException('Invalid app id'); } // Use $accessKey } }
2. Record Call Statistics
// Record successful call $this->apiCallerService->recordSuccess($accessKey); // Record failed call $this->apiCallerService->recordFailure($accessKey);
3. Get Statistics Data
use Tourze\AccessKeyBundle\Service\StatisticsService; class StatisticsController { public function __construct( private StatisticsService $statisticsService ) {} public function getStats(AccessKey $accessKey): array { // Today's statistics $todayStats = $this->statisticsService->getTodayStatistics($accessKey); // Weekly statistics $weeklyStats = $this->statisticsService->getWeeklyStatistics($accessKey); // Monthly statistics $monthlyStats = $this->statisticsService->getMonthlyStatistics($accessKey); // Custom date range statistics $customStats = $this->statisticsService->getSummary( $accessKey, new \DateTimeImmutable('2023-01-01'), new \DateTimeImmutable('2023-12-31') ); return compact('todayStats', 'weeklyStats', 'monthlyStats', 'customStats'); } }
Data Models
AccessKey Entity
title: Name (required, max 60 characters)appId: Application ID (required, max 64 characters, unique)appSecret: Application secret (optional, max 120 characters)allowIps: Allowed IP list (JSON array)signTimeoutSecond: Signature timeout in seconds (default 180)aesKey: AES encryption key (optional)remark: Remarks (optional)valid: Is valid (boolean, default false)owner: Owner (user reference)
AccessKeyStatistics Entity
accessKey: Associated access keyhour: Statistics time (hourly)successCount: Success countfailureCount: Failure counttotalCount: Total countsuccessRate: Success rate
Admin Panel
Bundle integrates with EasyAdmin for management interface:
- Create, edit, delete access keys
- View usage statistics
- Manage IP whitelist
- Configure signature parameters
Access path: /admin -> Access Keys
Permission Requirements
- All operations require
ROLE_ADMINpermission - Ensure users have appropriate permissions to access management features
Bundle Dependencies
doctrine/orm: Database ORMeasycorp/easyadmin-bundle: Admin paneltourze/doctrine-snowflake-bundle: Snowflake IDtourze/doctrine-timestamp-bundle: Timestampstourze/doctrine-track-bundle: Change tracking
License
MIT