Skip to content

Commit 7a165e5

Browse files
MDL-79669 lib: Update PHP-jwt to 6.10.0
1 parent 38a3310 commit 7a165e5

6 files changed

+73
-10
lines changed

lib/php-jwt/CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## [6.10.0](https://github.com/firebase/php-jwt/compare/v6.9.0...v6.10.0) (2023-11-28)
4+
5+
6+
### Features
7+
8+
* allow typ header override ([#546](https://github.com/firebase/php-jwt/issues/546)) ([79cb30b](https://github.com/firebase/php-jwt/commit/79cb30b729a22931b2fbd6b53f20629a83031ba9))
9+
10+
## [6.9.0](https://github.com/firebase/php-jwt/compare/v6.8.1...v6.9.0) (2023-10-04)
11+
12+
13+
### Features
14+
15+
* add payload to jwt exception ([#521](https://github.com/firebase/php-jwt/issues/521)) ([175edf9](https://github.com/firebase/php-jwt/commit/175edf958bb61922ec135b2333acf5622f2238a2))
16+
317
## [6.8.1](https://github.com/firebase/php-jwt/compare/v6.8.0...v6.8.1) (2023-07-14)
418

519

lib/php-jwt/src/BeforeValidException.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
namespace Firebase\JWT;
44

5-
class BeforeValidException extends \UnexpectedValueException
5+
class BeforeValidException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface
66
{
7+
private object $payload;
8+
9+
public function setPayload(object $payload): void
10+
{
11+
$this->payload = $payload;
12+
}
13+
14+
public function getPayload(): object
15+
{
16+
return $this->payload;
17+
}
718
}

lib/php-jwt/src/ExpiredException.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
namespace Firebase\JWT;
44

5-
class ExpiredException extends \UnexpectedValueException
5+
class ExpiredException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface
66
{
7+
private object $payload;
8+
9+
public function setPayload(object $payload): void
10+
{
11+
$this->payload = $payload;
12+
}
13+
14+
public function getPayload(): object
15+
{
16+
return $this->payload;
17+
}
718
}

lib/php-jwt/src/JWT.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,29 @@ public static function decode(
153153
// Check the nbf if it is defined. This is the time that the
154154
// token can actually be used. If it's not yet that time, abort.
155155
if (isset($payload->nbf) && floor($payload->nbf) > ($timestamp + static::$leeway)) {
156-
throw new BeforeValidException(
156+
$ex = new BeforeValidException(
157157
'Cannot handle token with nbf prior to ' . \date(DateTime::ISO8601, (int) $payload->nbf)
158158
);
159+
$ex->setPayload($payload);
160+
throw $ex;
159161
}
160162

161163
// Check that this token has been created before 'now'. This prevents
162164
// using tokens that have been created for later use (and haven't
163165
// correctly used the nbf claim).
164166
if (!isset($payload->nbf) && isset($payload->iat) && floor($payload->iat) > ($timestamp + static::$leeway)) {
165-
throw new BeforeValidException(
167+
$ex = new BeforeValidException(
166168
'Cannot handle token with iat prior to ' . \date(DateTime::ISO8601, (int) $payload->iat)
167169
);
170+
$ex->setPayload($payload);
171+
throw $ex;
168172
}
169173

170174
// Check if this token has expired.
171175
if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) {
172-
throw new ExpiredException('Expired token');
176+
$ex = new ExpiredException('Expired token');
177+
$ex->setPayload($payload);
178+
throw $ex;
173179
}
174180

175181
return $payload;
@@ -197,13 +203,14 @@ public static function encode(
197203
string $keyId = null,
198204
array $head = null
199205
): string {
200-
$header = ['typ' => 'JWT', 'alg' => $alg];
206+
$header = ['typ' => 'JWT'];
207+
if (isset($head) && \is_array($head)) {
208+
$header = \array_merge($header, $head);
209+
}
210+
$header['alg'] = $alg;
201211
if ($keyId !== null) {
202212
$header['kid'] = $keyId;
203213
}
204-
if (isset($head) && \is_array($head)) {
205-
$header = \array_merge($head, $header);
206-
}
207214
$segments = [];
208215
$segments[] = static::urlsafeB64Encode((string) static::jsonEncode($header));
209216
$segments[] = static::urlsafeB64Encode((string) static::jsonEncode($payload));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
namespace Firebase\JWT;
3+
4+
interface JWTExceptionWithPayloadInterface
5+
{
6+
/**
7+
* Get the payload that caused this exception.
8+
*
9+
* @return object
10+
*/
11+
public function getPayload(): object;
12+
13+
/**
14+
* Get the payload that caused this exception.
15+
*
16+
* @param object $payload
17+
* @return void
18+
*/
19+
public function setPayload(object $payload): void;
20+
}

lib/thirdpartylibs.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ All rights reserved.</copyright>
515515
<location>php-jwt</location>
516516
<name>A simple library to encode and decode JSON Web Tokens (JWT) in PHP, conforming to RFC 7519</name>
517517
<description>A simple library to encode and decode JSON Web Tokens (JWT) in PHP, conforming to RFC 7519</description>
518-
<version>6.8.1</version>
518+
<version>6.10.0</version>
519519
<license>BSD</license>
520520
<licenseversion>3-Clause</licenseversion>
521521
<repository>https://github.com/firebase/php-jwt</repository>

0 commit comments

Comments
 (0)