baywa-re-lusy / jwt-authentication
BayWa r.e. LUSY JWT Authentication
3.0.1
2024-06-21 07:29 UTC
Requires
- php: >=8.1
- ext-mbstring: *
- firebase/php-jwt: ^6.3
- guzzlehttp/guzzle: ^7.4
- guzzlehttp/psr7: ^2.4
- laminas/laminas-hydrator: ^4.3
- laminas/laminas-permissions-acl: ^2.10
- psr/cache: ^1.0
Requires (Dev)
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
README
Installation
To install the JWT Authentication service, you will need Composer in your project:
composer require baywa-re-lusy/jwt-authentication
Usage example code for Laminas projects
In Module.php
:
use BayWaReLusy\JwtAuthentication\TokenService; use Laminas\Cache\Psr\CacheItemPool\CacheItemPoolDecorator; use BayWaReLusy\JwtAuthentication\Token; public function onAuthentication(MvcAuthEvent $e): IdentityInterface { $jwt = ...; // The JSON Web Token $laminasCacheStorageInterface = ...; // Instance of Laminas\Cache\Storage\StorageInterface $jwksUrl = ...; // URL from where to get JWKs $cache = new CacheItemPoolDecorator($laminasCacheStorageInterface); $tokenService = new TokenService(); try { $token = $tokenService->validateToken($jwt, $cache, $jwksUrl); } catch (\BayWaReLusy\JwtAuthentication\InvalidTokenException $e) { return new GuestIdentity(); } ... }