Skip to content

Commit

Permalink
fix: Patch PHP-JWT for PHP 8.4 compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Nov 9, 2024
1 parent b91797d commit 557b657
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 6 deletions.
80 changes: 80 additions & 0 deletions .patches/firebase-php-jwt-572.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
diff --git a/src/CachedKeySet.php b/src/CachedKeySet.php
index 65bab74f..8e8e8d68 100644
--- a/src/CachedKeySet.php
+++ b/src/CachedKeySet.php
@@ -80,9 +80,9 @@ public function __construct(
ClientInterface $httpClient,
RequestFactoryInterface $httpFactory,
CacheItemPoolInterface $cache,
- int $expiresAfter = null,
+ ?int $expiresAfter = null,
bool $rateLimit = false,
- string $defaultAlg = null
+ ?string $defaultAlg = null
) {
$this->jwksUri = $jwksUri;
$this->httpClient = $httpClient;
@@ -180,7 +180,7 @@ private function keyIdExists(string $keyId): bool
$jwksResponse = $this->httpClient->sendRequest($request);
if ($jwksResponse->getStatusCode() !== 200) {
throw new UnexpectedValueException(
- sprintf('HTTP Error: %d %s for URI "%s"',
+ \sprintf('HTTP Error: %d %s for URI "%s"',
$jwksResponse->getStatusCode(),
$jwksResponse->getReasonPhrase(),
$this->jwksUri,
diff --git a/src/JWK.php b/src/JWK.php
index 63fb2484..6efc2fe3 100644
--- a/src/JWK.php
+++ b/src/JWK.php
@@ -52,7 +52,7 @@ class JWK
*
* @uses parseKey
*/
- public static function parseKeySet(array $jwks, string $defaultAlg = null): array
+ public static function parseKeySet(array $jwks, ?string $defaultAlg = null): array
{
$keys = [];

@@ -93,7 +93,7 @@ public static function parseKeySet(array $jwks, string $defaultAlg = null): arra
*
* @uses createPemFromModulusAndExponent
*/
- public static function parseKey(array $jwk, string $defaultAlg = null): ?Key
+ public static function parseKey(array $jwk, ?string $defaultAlg = null): ?Key
{
if (empty($jwk)) {
throw new InvalidArgumentException('JWK must not be empty');
@@ -212,7 +212,7 @@ private static function createPemFromCrvAndXYCoordinates(string $crv, string $x,
)
);

- return sprintf(
+ return \sprintf(
"-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n",
wordwrap(base64_encode($pem), 64, "\n", true)
);
diff --git a/src/JWT.php b/src/JWT.php
index e9d75639..9100bf0f 100644
--- a/src/JWT.php
+++ b/src/JWT.php
@@ -96,7 +96,7 @@ class JWT
public static function decode(
string $jwt,
$keyOrKeyArray,
- stdClass &$headers = null
+ ?stdClass &$headers = null
): stdClass {
// Validate JWT
$timestamp = \is_null(static::$timestamp) ? \time() : static::$timestamp;
@@ -200,8 +200,8 @@ public static function encode(
array $payload,
$key,
string $alg,
- string $keyId = null,
- array $head = null
+ ?string $keyId = null,
+ ?array $head = null
): string {
$header = ['typ' => 'JWT'];
if (isset($head) && \is_array($head)) {
2 changes: 2 additions & 0 deletions .patches/firebase-php-jwt-572.diff.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPDX-FileCopyrightText: 2024 Firebase PHP-JWT
SPDX-License-Identifier: BSD-3-Clause
11 changes: 11 additions & 0 deletions LICENSES/BSD-3-Clause.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright (c) <year> <owner>.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ appstore:
rsync -a \
--exclude=babel.config.js \
--exclude=/build \
--exclude=composer.patches.json \
--exclude=docs \
--exclude=.drone.jsonnet \
--exclude=.drone.yml \
Expand All @@ -91,6 +92,7 @@ appstore:
--exclude=mkdocs.yml \
--exclude=Makefile \
--exclude=node_modules \
--exclude=.patches \
--exclude=.php-cs-fixer.cache \
--exclude=.php-cs-fixer.dist.php \
--exclude=.php_cs.cache \
Expand Down
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ SPDX-FileCopyrightText = "2016 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "CC0-1.0"

[[annotations]]
path = ["package.json", "package-lock.json", ".git-blame-ignore-revs", "**/package.json", "**/package-lock.json", "composer.json", "composer.lock", "**/composer.json", "**/composer.lock", ".gitignore", ".l10nignore", "psalm.xml", "tests/psalm-baseline.xml", "vendor-bin/**/composer.json", "vendor-bin/**/composer.lock", ".tx/config", "**/phpunit.xml", "tsconfig.json", "redocly.yaml"]
path = ["package.json", "package-lock.json", ".git-blame-ignore-revs", "**/package.json", "**/package-lock.json", "composer.json", "composer.patches.json", "composer.lock", "**/composer.json", "**/composer.lock", ".gitignore", ".l10nignore", "psalm.xml", "tests/psalm-baseline.xml", "vendor-bin/**/composer.json", "vendor-bin/**/composer.lock", ".tx/config", "**/phpunit.xml", "tsconfig.json", "redocly.yaml"]
precedence = "aggregate"
SPDX-FileCopyrightText = "none"
SPDX-License-Identifier = "CC0-1.0"
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
},
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true
"bamarni/composer-bin-plugin": true,
"cweagans/composer-patches": true
},
"autoloader-suffix": "Talk",
"optimize-autoloader": true,
Expand Down Expand Up @@ -46,6 +47,7 @@
"require": {
"bamarni/composer-bin-plugin": "^1.8",
"cuyz/valinor": "^1.14",
"cweagans/composer-patches": "^1.7.3",
"firebase/php-jwt": "^6.10"
},
"extra": {
Expand All @@ -58,6 +60,7 @@
"firebase/php-jwt",
"cuyz/valinor"
]
}
},
"patches-file": "composer.patches.json"
}
}
54 changes: 51 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions composer.patches.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"patches": {
"firebase/php-jwt": {
"PHP 8.4 compatibility": ".patches/firebase-php-jwt-572.diff"
}
}
}

0 comments on commit 557b657

Please sign in to comment.