From b011d7165103e641d1452b657ed96c6dbd66a3ee Mon Sep 17 00:00:00 2001 From: emprove Date: Wed, 23 Dec 2020 09:56:39 +0300 Subject: [PATCH] fix for lcobucci/jwt 3.4 --- composer.json | 2 +- src/Centrifuge.php | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index df2e37a..7e804b5 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "php": "^7.2", "illuminate/broadcasting": "^6.0", "guzzlehttp/guzzle": "^6.3.3", - "lcobucci/jwt": "3.3.1" + "lcobucci/jwt": "^3.4" }, "require-dev": { "orchestra/testbench": "^3.3", diff --git a/src/Centrifuge.php b/src/Centrifuge.php index 328db70..e3d1d13 100644 --- a/src/Centrifuge.php +++ b/src/Centrifuge.php @@ -8,6 +8,7 @@ use LaraComponents\Centrifuge\Contracts\Centrifuge as CentrifugeContract; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Signer\Hmac\Sha256; +use Lcobucci\JWT\Signer\Key; class Centrifuge implements CentrifugeContract { @@ -270,14 +271,12 @@ protected function prepareUrl() */ public function generateToken(string $userId) { - $signer = new Sha256(); + $signer = new Sha256(); + $expiresAt = (new \DateTimeImmutable)->add(new \DateInterval("PT{$this->config['token_ttl']}S")); - $token = (new Builder())->setIssuer($this->config['token_issuer']) - ->setExpiration(now()->getTimestamp() + $this->config['token_ttl']) - ->set('sub', $userId) - ->sign($signer, $this->config['secret']) - ->getToken(); - - return $token; + return (new Builder())->issuedBy($this->config['token_issuer']) + ->expiresAt($expiresAt) + ->set('sub', $userId) + ->getToken($signer, new Key($this->config['secret'])); } }