diff --git a/CHANGELOG.md b/CHANGELOG.md index e08dfc90..ba3f7bb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ You can find and compare releases at the GitHub release page. ## [Unreleased] +### Added +- Support for lcobucci/jwt^5.0 (and dropped support for ^4.0) + +## [2.3.0] 2024-05-09 + ### Added - Support for Carbon 3 (and drop Carbon 1, but it was unused anyway) diff --git a/composer.json b/composer.json index e5438999..829bc665 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "illuminate/contracts": "^10|^11", "illuminate/http": "^10|^11", "illuminate/support": "^10|^11", - "lcobucci/jwt": "^4.0", + "lcobucci/jwt": "^5.0", "namshi/jose": "^7.0", "nesbot/carbon": "^2.0|^3.0" }, diff --git a/src/Providers/JWT/Lcobucci.php b/src/Providers/JWT/Lcobucci.php index 0a5be6e1..1da2e2a1 100644 --- a/src/Providers/JWT/Lcobucci.php +++ b/src/Providers/JWT/Lcobucci.php @@ -132,7 +132,7 @@ public function encode(array $payload) try { foreach ($payload as $key => $value) { - $this->addClaim($key, $value); + $this->builder = $this->addClaim($key, $value); } return $this->builder->getToken($this->config->signer(), $this->config->signingKey())->toString(); @@ -179,41 +179,22 @@ public function decode($token) * * @param string $key */ - protected function addClaim($key, $value) + protected function addClaim($key, $value): Builder { if (!isset($this->builder)) { $this->builder = $this->config->builder(); } - switch ($key) { - case RegisteredClaims::ID: - $this->builder->identifiedBy($value); - break; - case RegisteredClaims::EXPIRATION_TIME: - $this->builder->expiresAt(\DateTimeImmutable::createFromFormat('U', $value)); - break; - case RegisteredClaims::NOT_BEFORE: - $this->builder->canOnlyBeUsedAfter(\DateTimeImmutable::createFromFormat('U', $value)); - break; - case RegisteredClaims::ISSUED_AT: - $this->builder->issuedAt(\DateTimeImmutable::createFromFormat('U', $value)); - break; - case RegisteredClaims::ISSUER: - $this->builder->issuedBy($value); - break; - case RegisteredClaims::AUDIENCE: - if (is_array($value)) { - $this->builder->permittedFor(...$value); - } else { - $this->builder->permittedFor($value); - } - break; - case RegisteredClaims::SUBJECT: - $this->builder->relatedTo($value); - break; - default: - $this->builder->withClaim($key, $value); - } + return match ($key) { + RegisteredClaims::ID => $this->builder->identifiedBy($value), + RegisteredClaims::EXPIRATION_TIME => $this->builder->expiresAt(\DateTimeImmutable::createFromFormat('U', $value)), + RegisteredClaims::NOT_BEFORE => $this->builder->canOnlyBeUsedAfter(\DateTimeImmutable::createFromFormat('U', $value)), + RegisteredClaims::ISSUED_AT => $this->builder->issuedAt(\DateTimeImmutable::createFromFormat('U', $value)), + RegisteredClaims::ISSUER => $this->builder->issuedBy($value), + RegisteredClaims::AUDIENCE => is_array($value) ? $this->builder->permittedFor(...$value) : $this->builder->permittedFor($value), + RegisteredClaims::SUBJECT => $this->builder->relatedTo($value), + default => $this->builder->withClaim($key, $value), + }; } /** @@ -231,10 +212,6 @@ protected function getSigner() $signer = $this->signers[$this->algo]; - if (is_subclass_of($signer, Ecdsa::class)) { - return $signer::create(); - } - return new $signer(); }