Files

40 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2021-01-23 12:09:16 -08:00
<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
2021-01-23 12:09:16 -08:00
namespace Pterodactyl\Extensions\Lcobucci\JWT\Encoding;
2026-10-05 18:10:18 -04:00
use DateTimeImmutable;
2021-01-23 12:09:16 -08:00
use Lcobucci\JWT\ClaimsFormatter;
use Lcobucci\JWT\Token\RegisteredClaims;
2026-10-05 18:10:18 -04:00
use UnexpectedValueException;
2021-01-23 12:09:16 -08:00
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.
*/
2026-10-05 18:10:18 -04:00
/**
* @param JwtClaims $claims
* @return JwtClaims
*/
2021-01-23 12:09:16 -08:00
public function formatClaims(array $claims): array
{
foreach (RegisteredClaims::DATE_CLAIMS as $claim) {
2026-10-05 18:10:18 -04:00
if (! array_key_exists($claim, $claims)) {
2021-01-23 12:09:16 -08:00
continue;
}
2026-10-05 18:10:18 -04:00
$date = $claims[$claim];
throw_unless($date instanceof DateTimeImmutable, UnexpectedValueException::class, "JWT date claim [$claim] must be a DateTimeImmutable instance.");
$claims[$claim] = $date->getTimestamp();
2021-01-23 12:09:16 -08:00
}
return $claims;
}
}