Skip to content

Commit

Permalink
fix for lcobucci/jwt 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
emprove committed Dec 23, 2020
1 parent d8548be commit b011d71
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 7 additions & 8 deletions src/Centrifuge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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']));
}
}

0 comments on commit b011d71

Please sign in to comment.