Fix fatal error when firebase/php-jwt library is 'replaced' in composer
authorMatthew Wire <mjw@mjwconsult.co.uk>
Thu, 11 Jan 2024 12:46:57 +0000 (12:46 +0000)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Wed, 31 Jan 2024 21:13:54 +0000 (21:13 +0000)
Civi/Crypto/CryptoJwt.php

index bbc989ce2062f3add24e9cc0d8b3b39c76d92c94..0d5455d58e143354b83178a638603cc39f563db5 100644 (file)
@@ -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+.');
     }