A modular and extensible JWT authentication library built on top of firebase/php-jwt.
It provides a clean structure for generating, validating, refreshing, and customizing tokens with support for custom payloads and claim validation.
composer require yourname/jwt-authuse JwtAuth\Config\JwtConfig;
use JwtAuth\Claims\DefaultClaimsProvider;
use JwtAuth\Keys\LocalKeyProvider;
use JwtAuth\Services\TokenGenerator;
use JwtAuth\Services\TokenValidator;
use JwtAuth\Services\TokenRefresher;
use JwtAuth\Validation\DefaultClaimValidator;
use JwtAuth\Core\JwtManager;
$config = new JwtConfig(
issuer: 'my-app',
audience: 'my-users',
algorithm: 'RS256',
privateKeyPath: __DIR__ . '/keys/private.pem',
publicKeyPath: __DIR__ . '/keys/public.pem',
ttl: 3600
);
$keyProvider = new LocalKeyProvider($config->privateKeyPath, $config->publicKeyPath);
$claimsProvider = new DefaultClaimsProvider($config->issuer, $config->audience, $config->ttl);
$claimValidator = new DefaultClaimValidator();
$generator = new TokenGenerator($config, $claimsProvider, $keyProvider);
$validator = new TokenValidator($config, $keyProvider);
$refresher = new TokenRefresher($generator);
$jwtManager = new JwtManager($generator, $validator);
// Generate a token
$token = $jwtManager->createToken(['user_id' => 42]);
// Validate the token
$payload = $jwtManager->verifyToken($token);
// Refresh the token
$newToken = $refresher->refresh($payload);-
Generate JWT tokens with default or custom claims
-
Validate tokens and decode payloads securely
-
Refresh tokens using existing payload data
-
Extend or replace any component:
ClaimsProviderInterfacefor custom payload logicClaimValidatorInterfacefor custom validation rulesTokenPayloadInterfacefor custom payload objectsKeyProviderInterfacefor flexible key management (file, env, KMS, etc.)
src/
├── Claims/
├── Config/
├── Contracts/
├── Core/
├── Exceptions/
├── Keys/
├── Services/
└── Validation/
Each folder is modular and follows the single-responsibility principle, making the library scalable and easy to maintain.
Proprietary License.