Update logic for server transfer controller

This commit is contained in:
Dane Everitt 2020-12-24 10:10:40 -08:00
parent 6c61577699
commit 2ee08a1a3d
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
6 changed files with 178 additions and 131 deletions

View file

@ -22,6 +22,11 @@ class NodeJWTService
*/
private $expiresAt;
/**
* @var string|null
*/
private $subject;
/**
* Set the claims to include in this JWT.
*
@ -35,6 +40,10 @@ class NodeJWTService
return $this;
}
/**
* @param \DateTimeInterface $date
* @return $this
*/
public function setExpiresAt(DateTimeInterface $date)
{
$this->expiresAt = $date->getTimestamp();
@ -42,20 +51,32 @@ class NodeJWTService
return $this;
}
/**
* @param string $subject
* @return $this
*/
public function setSubject(string $subject)
{
$this->subject = $subject;
return $this;
}
/**
* Generate a new JWT for a given node.
*
* @param \Pterodactyl\Models\Node $node
* @param string|null $identifiedBy
* @param string $algo
* @return \Lcobucci\JWT\Token
*/
public function handle(Node $node, string $identifiedBy)
public function handle(Node $node, string $identifiedBy, string $algo = 'md5')
{
$signer = new Sha256;
$builder = (new Builder)->issuedBy(config('app.url'))
->permittedFor($node->getConnectionAddress())
->identifiedBy(md5($identifiedBy), true)
->identifiedBy(hash($algo, $identifiedBy), true)
->issuedAt(CarbonImmutable::now()->getTimestamp())
->canOnlyBeUsedAfter(CarbonImmutable::now()->subMinutes(5)->getTimestamp());
@ -63,6 +84,10 @@ class NodeJWTService
$builder = $builder->expiresAt($this->expiresAt);
}
if (!empty($this->subject)) {
$builder = $builder->relatedTo($this->subject, true);
}
foreach ($this->claims as $key => $value) {
$builder = $builder->withClaim($key, $value);
}