Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fatal error when firebase/php-jwt library is 'replaced' in composer #28971

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Civi/Crypto/CryptoJwt.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ public function encode($payload, $keyIdOrTag = 'SIGN') {
* @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;
Copy link
Member

@totten totten Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this conditional distinguishes Firbase JWT v5.x from v6.0 -- but then it misinterprets v6.6+.

So if your build has v6.6 (as in the D9 E2E tests), then it misfires and gives it the v5.x data:

Error: Cannot pass parameter 3 by reference in Civi\Crypto\CryptoJwt->decode() (line 92 of /Users/totten/bknix/build/build-0/vendor/civicrm/civicrm-core/Civi/Crypto/CryptoJwt.php)

#0 /Users/totten/bknix/build/build-0/vendor/civicrm/civicrm-core/ext/authx/Civi/Authx/CheckCredential.php(96): Civi\Crypto\CryptoJwt->decode('')
#1 [internal function]: Civi\Authx\CheckCredential->bearerJwt(Object(Civi\Authx\CheckCredentialEvent), 'civi.authx.chec...', Object(Civi\Core\UnoptimizedEventDispatcher))


// 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+.');
}
Expand Down