Update to Laravel 8
Co-authored-by: Matthew Penner <me@matthewp.io>
This commit is contained in:
parent
028921b42a
commit
a043071e3c
211 changed files with 4394 additions and 2933 deletions
|
@ -2,13 +2,14 @@
|
|||
|
||||
namespace Pterodactyl\Services\Nodes;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Lcobucci\JWT\Builder;
|
||||
use DateTimeImmutable;
|
||||
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;
|
||||
use Pterodactyl\Extensions\Lcobucci\JWT\Encoding\TimestampDates;
|
||||
|
||||
class NodeJWTService
|
||||
{
|
||||
|
@ -18,7 +19,7 @@ class NodeJWTService
|
|||
private $claims = [];
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
* @var \DateTimeImmutable|null
|
||||
*/
|
||||
private $expiresAt;
|
||||
|
||||
|
@ -41,12 +42,12 @@ class NodeJWTService
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface $date
|
||||
* @param \DateTimeImmutable $date
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpiresAt(DateTimeInterface $date)
|
||||
public function setExpiresAt(DateTimeImmutable $date)
|
||||
{
|
||||
$this->expiresAt = $date->getTimestamp();
|
||||
$this->expiresAt = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -68,24 +69,27 @@ 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(new TimestampDates)
|
||||
->issuedBy(config('app.url'))
|
||||
->permittedFor($node->getConnectionAddress())
|
||||
->identifiedBy(hash($algo, $identifiedBy), true)
|
||||
->issuedAt(CarbonImmutable::now()->getTimestamp())
|
||||
->canOnlyBeUsedAfter(CarbonImmutable::now()->subMinutes(5)->getTimestamp());
|
||||
->identifiedBy($identifier)
|
||||
->withHeader('jti', $identifier)
|
||||
->issuedAt(CarbonImmutable::now())
|
||||
->canOnlyBeUsedAfter(CarbonImmutable::now()->subMinutes(5));
|
||||
|
||||
if ($this->expiresAt) {
|
||||
$builder = $builder->expiresAt($this->expiresAt);
|
||||
}
|
||||
|
||||
if (!empty($this->subject)) {
|
||||
$builder = $builder->relatedTo($this->subject, true);
|
||||
if (! empty($this->subject)) {
|
||||
$builder = $builder->relatedTo($this->subject)->withHeader('sub', $this->subject);
|
||||
}
|
||||
|
||||
foreach ($this->claims as $key => $value) {
|
||||
|
@ -94,6 +98,6 @@ class NodeJWTService
|
|||
|
||||
return $builder
|
||||
->withClaim('unique_id', Str::random(16))
|
||||
->getToken($signer, new Key($node->getDecryptedKey()));
|
||||
->getToken($config->signer(), $config->signingKey());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue