Integrates the firebase/php-jwt library with phpnomad/auth's JwtStrategy interface. It provides a single concrete strategy that encodes payloads into HS256-signed JSON Web Tokens and decodes them back into arrays, translating firebase/php-jwt's exception types into PHPNomad\Auth\Exceptions\JwtException so the rest of your application only has to catch one thing.
composer require phpnomad/firebase-jwt-integration- A
FirebaseJwtstrategy class that implementsPHPNomad\Auth\Interfaces\JwtStrategyusingfirebase/php-jwt, with HS256 for both encoding and verification. - Exception translation that maps
ExpiredException,SignatureInvalidException,BeforeValidException, and the standard PHP value errors intoPHPNomad\Auth\Exceptions\JwtExceptionwith descriptive messages.
phpnomad/auth ^1.0for theJwtStrategyinterface and itsJwtExceptiontype.firebase/php-jwt ^6.10as the underlying JWT library.
Bind FirebaseJwt to the JwtStrategy interface inside one of your bootstrapper initializers. Any service that depends on JwtStrategy will then receive this implementation without knowing which library is wired in behind it.
<?php
namespace MyApp\Strategies;
use PHPNomad\Auth\Interfaces\JwtStrategy;
use PHPNomad\JWT\Firebase\Integration\Strategies\FirebaseJwt;
use PHPNomad\Loader\Interfaces\HasClassDefinitions;
final class JwtInitializer implements HasClassDefinitions
{
public function getClassDefinitions(): array
{
return [
FirebaseJwt::class => JwtStrategy::class,
];
}
}With that binding in place, a service can take JwtStrategy as a constructor dependency and call $jwt->encode($payload, $secret) or $jwt->decode($token, $secret) without ever referencing FirebaseJwt directly.
See the bootstrapping and strategy binding guides at phpnomad.com. For details on the underlying library, configuration options, and supported algorithms, see firebase/php-jwt.
Released under the MIT License. See LICENSE.txt.