mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
40 lines
1.2 KiB
PHP
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;
|
|
}
|
|
}
|