Files
pterodactyl-panel/app/Extensions/Lcobucci/JWT/Encoding/TimestampDates.php
T
6c0413e39b Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co>
Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
2026-10-05 18:10:18 -04:00

40 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Pterodactyl\Extensions\Lcobucci\JWT\Encoding;
use DateTimeImmutable;
use Lcobucci\JWT\ClaimsFormatter;
use Lcobucci\JWT\Token\RegisteredClaims;
use UnexpectedValueException;
final class TimestampDates implements ClaimsFormatter
{
/**
* The default time encoder for JWTs using this library is not supported correctly
* by Wings and will cause a flood of errors and panic conditions because the times
* cannot be parsed correctly. The default is time with microseconds, we just need
* to use the normal unix timestamp here.
*/
/**
* @param JwtClaims $claims
* @return JwtClaims
*/
public function formatClaims(array $claims): array
{
foreach (RegisteredClaims::DATE_CLAIMS as $claim) {
if (! array_key_exists($claim, $claims)) {
continue;
}
$date = $claims[$claim];
throw_unless($date instanceof DateTimeImmutable, UnexpectedValueException::class, "JWT date claim [$claim] must be a DateTimeImmutable instance.");
$claims[$claim] = $date->getTimestamp();
}
return $claims;
}
}