getkeymanager/php-sdk
PHP SDK for integrating with GetKeyManager: manage API keys and access securely from your Laravel or PHP apps. Simple client setup, request helpers, and authentication support to streamline key creation, retrieval, rotation, and usage.
## Technical Evaluation
### **Architecture Fit**
- **Monolithic vs. Microservices**:
- **Monolithic**: Unchanged; direct Composer integration remains viable. Middleware/service layer integration still optimal.
- **Microservices**: New **async validation webhooks** (3.3.0) enable event-driven architectures. Requires Laravel queue/listener setup (e.g., `Illuminate\Queue\Listeners`) to process webhook payloads.
- **Event-Driven**: Now **partially supported** via webhooks (e.g., license expiration events). Requires Laravel’s queue system for async handling.
- **State Management**:
- **New**: Local license storage API (`LicenseManager::storeLocally()`) for offline scenarios. Reduces risk of offline failures.
- **Caching**: Redis integration remains recommended; new `cacheTTL` config option in SDK (default: 3600s).
### **Integration Feasibility**
- **PHP/Laravel Compatibility**:
- **Pros**:
- New **Laravel facade** (`GetKeyManager\Facades\License`) reduces boilerplate.
- Webhook listeners now natively supported via `LicenseWebhookHandler` trait.
- **Cons**:
- **Breaking**: `LicenseManager::validate()` signature changed (now returns `LicenseResponse` object instead of bool).
- **Workaround**: Update calls to:
```php
$response = app(LicenseManager::class)->validate();
if (!$response->isValid()) { ... }
```
- **Dependency Conflicts**:
- New dependency: `symfony/event-dispatcher` (for webhooks). Check for conflicts with Laravel’s event system.
- **Dependency Conflicts**:
- Low risk for core functionality. **New**: `symfony/event-dispatcher` may conflict with Laravel’s `illuminate/events` if not namespaced properly.
- **Mitigation**: Use `composer why-not symfony/event-dispatcher` and alias in `composer.json` if needed.
### **Technical Risk**
| **Risk Area** | **Severity** | **Mitigation** |
|-----------------------------|-------------|---------------------------------------------------------------------------------|
| **Webhook Reliability** | High | Implement Laravel’s `failed_jobs` table monitoring and retry logic. |
| **Breaking Changes** | High | Update all `validate()` calls; test with `phpunit` and `pest`. |
| **Event-Dispatcher Conflict**| Medium | Isolate SDK events in a custom namespace or use Laravel’s event system. |
| **Local Storage Security** | Medium | Encrypt locally stored licenses (e.g., `storage/encrypted/licenses`). |
| **Rate Limits** | High | New `retryAfter` field in `LicenseResponse`; implement exponential backoff. |
### **Key Questions**
1. **Webhook Integration Depth**:
- Does the app need to react to **all** webhook events (e.g., `license.activated`, `license.expired`) or only specific ones?
- *Impact*: May require custom event handlers or Laravel’s `HandleJobsMiddleware`.
2. **Local Storage Encryption**:
- How sensitive are license keys? Does the app need **end-to-end encryption** for locally stored licenses?
- *Impact*: SDK provides `storeLocally()` but not encryption; may need `openssl` integration.
3. **Webhook Authentication**:
- How will Laravel verify webhook payloads (e.g., HMAC signatures)?
- *Impact*: SDK requires `webhookSecret` config; ensure `.env` is secure.
4. **Queue Backpressure**:
- Under high load, could webhook processing overwhelm Laravel’s queue?
- *Impact*: Monitor `failed_jobs` table; consider batching or dedicated queue workers.
5. **Multi-Region Deployments**:
- Will webhooks be processed globally, or is regional failover needed?
- *Impact*: SDK webhooks are HTTP-based; may need CDN or regional queue workers.
---
## Integration Approach
### **Stack Fit**
- **PHP/Laravel Alignment**:
- **Strengths**:
- **Facade**: `GetKeyManager\Facades\License` reduces manual DI.
- **Webhooks**: Native integration with Laravel’s queue system (e.g., `LicenseWebhookHandler`).
- **Local Storage**: `LicenseManager::storeLocally()` aligns with Laravel’s `storage/` directory.
- **Gaps**:
- **Event System**: SDK’s `symfony/event-dispatcher` may conflict with Laravel’s. Use Laravel’s events instead:
```php
event(new LicenseExpired($license));
```
- **No Queue Worker**: Webhook processing requires manual queue setup (e.g., `php artisan queue:work`).
- **Alternative Stacks**:
- **Symfony**: Better alignment with SDK’s event system.
- **Non-PHP**: Requires proxy service for webhooks (e.g., AWS Lambda).
### **Migration Path**
1. **Phase 1: SDK Update (1 day)**
- Update Composer: `composer require getkeymanager/php-sdk:^3.3.0`.
- Update `validate()` calls to use `LicenseResponse` object.
- Add facade to `config/app.php`:
```php
'aliases' => [
'License' => GetKeyManager\Facades\License::class,
],
```
2. **Phase 2: Webhook Setup (3–5 days)**
- Configure webhook endpoint in `routes/web.php`:
```php
Route::post('/license-webhook', [LicenseWebhookHandler::class, 'handle']);
```
- Set up queue listener in `app/Providers/QueueServiceProvider.php`:
```php
$this->app->booted(function () {
$this->app->make('Illuminate\Contracts\Queue\Queue')
->listen('license-webhook', LicenseWebhookHandler::class);
});
.env:
LICENSE_WEBHOOK_SECRET=your_secret_here
QUEUE_CONNECTION=redis
// app/Services/LocalLicenseStorage.php
public function store($licenseData)
{
File::put(storage_path('encrypted/licenses/current.json'), $this->encrypt($licenseData));
}
// app/Http/Middleware/SyncLicenseOnReconnect.php
public function handle($request, Closure $next)
{
if (app(LicenseManager::class)->isOffline()) {
app(LocalLicenseStorage::class)->syncWithCloud();
}
return $next($request);
}
Laravel Versions:
symfony/event-dispatcher).php artisan package:discover to resolve facade conflicts.PHP Extensions:
openssl required for local license encryption.php.ini or Dockerfile:
extension=openssl
Database:
licenses table for audit logs:
Schema::create('licenses', function (Blueprint $table) {
$table->id();
$table->text('payload');
$table->timestamp('expires_at')->nullable();
$table->timestamps();
});
Prerequisites:
Critical Path:
Non-Critical:
Dependencies:
symfony/event-dispatcher for updates.composer why-not to CI pipeline to catch conflicts early.LicenseManager::check() in favor of validate().Configuration Drift:
config/license.php:
return [
'webhook_secret' => env('LICENSE_WEBHOOK_SECRET'),
'local_storage_path' => storage_path('encrypted/licenses'),
'webhook_events' => ['license.activated', 'license.expired'],
];
Deprecation:
LicenseManager::check() removed in 3.3.0. Update all usages.phpstan to detect deprecated method calls.How can I help you explore Laravel packages today?