habityzer / kinde-bundle
Symfony bundle for Kinde authentication integration with JWT validation, webhooks, and user sync
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/habityzer/kinde-bundle
Requires
- php: >=8.2
- firebase/php-jwt: ^6.0
- kinde-oss/kinde-auth-php: ^2.3
- symfony/cache: ^6.4|^7.0
- symfony/event-dispatcher: ^6.4|^7.0
- symfony/framework-bundle: ^6.4|^7.0
- symfony/http-client: ^6.4|^7.0
- symfony/security-bundle: ^6.4|^7.0
Requires (Dev)
- phpunit/phpunit: ^10.0
- symfony/phpunit-bridge: ^6.4|^7.0
This package is auto-updated.
Last update: 2025-10-14 09:16:26 UTC
README
Symfony bundle for Kinde authentication integration with JWT validation, webhooks, and user synchronization.
Features
- ✅ JWT Token Validation - Validates Kinde tokens using JWKS
- ✅ Symfony Security Integration - Custom authenticator for seamless integration
- ✅ User Synchronization - Sync users from Kinde to your database
- ✅ Webhook Support - Handle Kinde webhook events (user updates, subscriptions)
- ✅ Event-Driven - Dispatch Symfony events for business logic
- ✅ Fully Decoupled - Uses interfaces for app-specific logic
Installation
composer require habityzer/kinde-bundle
The bundle installs successfully without configuration, but you must configure it before using:
1. Set Environment Variables
Add to your .env
file:
KINDE_DOMAIN=https://your-business.kinde.com KINDE_CLIENT_ID=your-client-id-from-kinde KINDE_CLIENT_SECRET=your-client-secret KINDE_WEBHOOK_SECRET=your-webhook-secret
Get these values from your Kinde Dashboard.
2. Create Configuration File
Create config/packages/habityzer_kinde.yaml
:
habityzer_kinde: domain: '%env(KINDE_DOMAIN)%' client_id: '%env(KINDE_CLIENT_ID)%' client_secret: '%env(KINDE_CLIENT_SECRET)%' webhook_secret: '%env(KINDE_WEBHOOK_SECRET)%'
3. Clear Cache
php bin/console cache:clear
Note: The bundle will throw helpful runtime errors if you try to use authentication without proper configuration.
Configuration
# config/packages/habityzer_kinde.yaml habityzer_kinde: domain: '%env(KINDE_DOMAIN)%' client_id: '%env(KINDE_CLIENT_ID)%' client_secret: '%env(KINDE_CLIENT_SECRET)%' webhook_secret: '%env(KINDE_WEBHOOK_SECRET)%' # Optional jwks_cache_ttl: 3600 # Cache JWKS for 1 hour
Usage
1. Implement the User Provider Interface
namespace App\Kinde; use Habityzer\KindeBundle\Contract\KindeUserProviderInterface; use App\Entity\User; class UserProvider implements KindeUserProviderInterface { public function findByKindeId(string $kindeId): ?object { return $this->userRepository->findOneBy(['kindeId' => $kindeId]); } public function syncUser(array $kindeUserData): object { $user = new User(); $user->setKindeId($kindeUserData['kinde_id']); $user->setEmail($kindeUserData['email']); $user->setName($kindeUserData['name']); // ... your logic $this->em->persist($user); $this->em->flush(); return $user; } public function updateUser(object $user, array $kindeUserData): void { $user->setEmail($kindeUserData['email']); $user->setName($kindeUserData['name']); // ... your update logic $this->em->flush(); } public function handleUserDeletion(object $user): void { $user->setKindeId(null); // Soft delete $this->em->flush(); } }
2. Subscribe to Webhook Events
namespace App\EventSubscriber; use Habityzer\KindeBundle\Event\KindeEvents; use Habityzer\KindeBundle\Event\KindeSubscriptionUpdatedEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class KindeWebhookSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents(): array { return [ KindeEvents::SUBSCRIPTION_UPDATED => 'onSubscriptionUpdated', KindeEvents::USER_UPDATED => 'onUserUpdated', ]; } public function onSubscriptionUpdated(KindeSubscriptionUpdatedEvent $event): void { // Your business logic $userId = $event->getUserId(); $planName = $event->getPlanName(); $this->billingService->updateUserPlan($userId, $planName); } }
3. Enable Security Authenticator
# config/packages/security.yaml security: firewalls: api: custom_authenticators: - Habityzer\KindeBundle\Security\KindeTokenAuthenticator
Events
The bundle dispatches the following events:
kinde.user.updated
- User information updatedkinde.user.deleted
- User deleted from Kindekinde.user.authenticated
- User authenticatedkinde.subscription.created
- Subscription createdkinde.subscription.updated
- Subscription updatedkinde.subscription.cancelled
- Subscription cancelledkinde.subscription.reactivated
- Subscription reactivated
Requirements
- PHP 8.2 or higher
- Symfony 6.4 or 7.x
- Kinde account with configured application
License
MIT
Support
For issues and questions: https://github.com/habityzer/kinde-bundle/issues