Update JWT library to support PHP 8; bumps minimum PHP version for Pterodactyl to 7.4

This commit is contained in:
Dane Everitt
2021-01-20 21:21:28 -08:00
parent 988b711ea2
commit 8dbf60de2c
4 changed files with 134 additions and 66 deletions

View File

@@ -3,12 +3,12 @@
namespace Pterodactyl\Services\Nodes;
use DateTimeImmutable;
use Lcobucci\JWT\Builder;
use Carbon\CarbonImmutable;
use Illuminate\Support\Str;
use Lcobucci\JWT\Signer\Key;
use Pterodactyl\Models\Node;
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Lcobucci\JWT\Signer\Key\InMemory;
class NodeJWTService
{
@@ -68,15 +68,15 @@ class NodeJWTService
* @param \Pterodactyl\Models\Node $node
* @param string|null $identifiedBy
* @param string $algo
* @return \Lcobucci\JWT\Token
* @return \Lcobucci\JWT\Token\Plain
*/
public function handle(Node $node, string $identifiedBy, string $algo = 'md5')
{
$signer = new Sha256;
$identifier = hash($algo, $identifiedBy);
$config = Configuration::forSymmetricSigner(new Sha256, InMemory::plainText($node->getDecryptedKey()));
$builder = (new Builder)->issuedBy(config('app.url'))
$builder = $config->builder()
->issuedBy(config('app.url'))
->permittedFor($node->getConnectionAddress())
->identifiedBy($identifier)
->withHeader('jti', $identifier)
@@ -97,6 +97,6 @@ class NodeJWTService
return $builder
->withClaim('unique_id', Str::random(16))
->getToken($signer, new Key($node->getDecryptedKey()));
->getToken($config->signer(), $config->signingKey());
}
}