Skip to content

Commit

Permalink
MDL-79669 lib: Update PHP-jwt to 6.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocolate-lightning committed Mar 12, 2024
1 parent 38a3310 commit 7a165e5
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 10 deletions.
14 changes: 14 additions & 0 deletions lib/php-jwt/CHANGELOG.md
@@ -1,5 +1,19 @@
# Changelog

## [6.10.0](https://github.com/firebase/php-jwt/compare/v6.9.0...v6.10.0) (2023-11-28)


### Features

* allow typ header override ([#546](https://github.com/firebase/php-jwt/issues/546)) ([79cb30b](https://github.com/firebase/php-jwt/commit/79cb30b729a22931b2fbd6b53f20629a83031ba9))

## [6.9.0](https://github.com/firebase/php-jwt/compare/v6.8.1...v6.9.0) (2023-10-04)


### Features

* add payload to jwt exception ([#521](https://github.com/firebase/php-jwt/issues/521)) ([175edf9](https://github.com/firebase/php-jwt/commit/175edf958bb61922ec135b2333acf5622f2238a2))

## [6.8.1](https://github.com/firebase/php-jwt/compare/v6.8.0...v6.8.1) (2023-07-14)


Expand Down
13 changes: 12 additions & 1 deletion lib/php-jwt/src/BeforeValidException.php
Expand Up @@ -2,6 +2,17 @@

namespace Firebase\JWT;

class BeforeValidException extends \UnexpectedValueException
class BeforeValidException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface
{
private object $payload;

public function setPayload(object $payload): void
{
$this->payload = $payload;
}

public function getPayload(): object
{
return $this->payload;
}
}
13 changes: 12 additions & 1 deletion lib/php-jwt/src/ExpiredException.php
Expand Up @@ -2,6 +2,17 @@

namespace Firebase\JWT;

class ExpiredException extends \UnexpectedValueException
class ExpiredException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface
{
private object $payload;

public function setPayload(object $payload): void
{
$this->payload = $payload;
}

public function getPayload(): object
{
return $this->payload;
}
}
21 changes: 14 additions & 7 deletions lib/php-jwt/src/JWT.php
Expand Up @@ -153,23 +153,29 @@ public static function decode(
// Check the nbf if it is defined. This is the time that the
// token can actually be used. If it's not yet that time, abort.
if (isset($payload->nbf) && floor($payload->nbf) > ($timestamp + static::$leeway)) {
throw new BeforeValidException(
$ex = new BeforeValidException(
'Cannot handle token with nbf prior to ' . \date(DateTime::ISO8601, (int) $payload->nbf)
);
$ex->setPayload($payload);
throw $ex;
}

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

// Check if this token has expired.
if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) {
throw new ExpiredException('Expired token');
$ex = new ExpiredException('Expired token');
$ex->setPayload($payload);
throw $ex;
}

return $payload;
Expand Down Expand Up @@ -197,13 +203,14 @@ public static function encode(
string $keyId = null,
array $head = null
): string {
$header = ['typ' => 'JWT', 'alg' => $alg];
$header = ['typ' => 'JWT'];
if (isset($head) && \is_array($head)) {
$header = \array_merge($header, $head);
}
$header['alg'] = $alg;
if ($keyId !== null) {
$header['kid'] = $keyId;
}
if (isset($head) && \is_array($head)) {
$header = \array_merge($head, $header);
}
$segments = [];
$segments[] = static::urlsafeB64Encode((string) static::jsonEncode($header));
$segments[] = static::urlsafeB64Encode((string) static::jsonEncode($payload));
Expand Down
20 changes: 20 additions & 0 deletions lib/php-jwt/src/JWTExceptionWithPayloadInterface.php
@@ -0,0 +1,20 @@
<?php
namespace Firebase\JWT;

interface JWTExceptionWithPayloadInterface
{
/**
* Get the payload that caused this exception.
*
* @return object
*/
public function getPayload(): object;

/**
* Get the payload that caused this exception.
*
* @param object $payload
* @return void
*/
public function setPayload(object $payload): void;
}
2 changes: 1 addition & 1 deletion lib/thirdpartylibs.xml
Expand Up @@ -515,7 +515,7 @@ All rights reserved.</copyright>
<location>php-jwt</location>
<name>A simple library to encode and decode JSON Web Tokens (JWT) in PHP, conforming to RFC 7519</name>
<description>A simple library to encode and decode JSON Web Tokens (JWT) in PHP, conforming to RFC 7519</description>
<version>6.8.1</version>
<version>6.10.0</version>
<license>BSD</license>
<licenseversion>3-Clause</licenseversion>
<repository>https://github.com/firebase/php-jwt</repository>
Expand Down

0 comments on commit 7a165e5

Please sign in to comment.