From 645ba6bbff02cd6eff31502d01214d7a2ed01953 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Thu, 11 Jan 2024 12:46:57 +0000 Subject: [PATCH] Fix fatal error when firebase/php-jwt library is 'replaced' in composer --- Civi/Crypto/CryptoJwt.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Civi/Crypto/CryptoJwt.php b/Civi/Crypto/CryptoJwt.php index bbc989ce20..0d5455d58e 100644 --- a/Civi/Crypto/CryptoJwt.php +++ b/Civi/Crypto/CryptoJwt.php @@ -60,7 +60,12 @@ class CryptoJwt { * @throws CryptoException */ public function decode($token, $keyTag = 'SIGN') { - $useKeyObj = version_compare(\Composer\InstalledVersions::getVersion('firebase/php-jwt'), '6', '>='); + // Version 6.x+ has 2 parameters, earlier versions had 3 + $reflection = new \ReflectionMethod('Firebase\JWT\JWT::decode'); + $useKeyObj = ($reflection->getNumberOfParameters() === 2) ?? FALSE; + + // Composer\InstalledVersions returns 0 if the library has been replaced using "replace" in composer.json + // $useKeyObj = version_compare(\Composer\InstalledVersions::getVersion('firebase/php-jwt'), '6', '>='); if (!$useKeyObj) { \CRM_Core_Error::deprecatedWarning('Using deprecated version of firebase/php-jwt. Upgrade to 6.x+.'); } -- 2.25.1