JWT encoding, decoding, and key routing for Switon Framework.
composer require switon/jwtRequirements: PHP 8.3+
use Switon\Core\Attribute\Autowired;
use Switon\Jwt\JwtInterface;
class AuthService
{
#[Autowired] protected JwtInterface $jwt;
public function issue(int $userId): string
{
return $this->jwt->encode(['user_id' => $userId], 3600);
}
public function authenticate(string $token): array
{
return $this->jwt->decode($token);
}
}Docs: https://docs.switon.dev/latest/jwt
MIT.