diff --git a/composer.json b/composer.json index 6c750ad8..4b09368d 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "illuminate/contracts": "^9.0|^10.0|^11.0", "illuminate/http": "^9.0|^10.0|^11.0", "illuminate/support": "^9.0|^10.0|^11.0", - "lcobucci/jwt": "^4.0", + "lcobucci/jwt": "^4.0|^5.0", "nesbot/carbon": "^2.0|^3.0" }, "require-dev": { diff --git a/src/Providers/JWT/Lcobucci.php b/src/Providers/JWT/Lcobucci.php index 4e08e561..ce394e2d 100644 --- a/src/Providers/JWT/Lcobucci.php +++ b/src/Providers/JWT/Lcobucci.php @@ -11,6 +11,7 @@ namespace Tymon\JWTAuth\Providers\JWT; +use Composer\InstalledVersions; use DateTimeImmutable; use DateTimeInterface; use Exception; @@ -142,28 +143,28 @@ protected function getBuilderFromClaims(array $payload): Builder foreach ($payload as $key => $value) { switch ($key) { case RegisteredClaims::ID: - $builder->identifiedBy($value); + $builder = $builder->identifiedBy($value); break; case RegisteredClaims::EXPIRATION_TIME: - $builder->expiresAt(DateTimeImmutable::createFromFormat('U', $value)); + $builder = $builder->expiresAt(DateTimeImmutable::createFromFormat('U', $value)); break; case RegisteredClaims::NOT_BEFORE: - $builder->canOnlyBeUsedAfter(DateTimeImmutable::createFromFormat('U', $value)); + $builder = $builder->canOnlyBeUsedAfter(DateTimeImmutable::createFromFormat('U', $value)); break; case RegisteredClaims::ISSUED_AT: - $builder->issuedAt(DateTimeImmutable::createFromFormat('U', $value)); + $builder = $builder->issuedAt(DateTimeImmutable::createFromFormat('U', $value)); break; case RegisteredClaims::ISSUER: - $builder->issuedBy($value); + $builder = $builder->issuedBy($value); break; case RegisteredClaims::AUDIENCE: - $builder->permittedFor($value); + $builder = $builder->permittedFor($value); break; case RegisteredClaims::SUBJECT: - $builder->relatedTo($value); + $builder = $builder->relatedTo($value); break; default: - $builder->withClaim($key, $value); + $builder = $builder->withClaim($key, $value); } } @@ -207,13 +208,20 @@ protected function getSigner() $signer = $this->signers[$this->algo]; - if (is_subclass_of($signer, Ecdsa::class)) { + // v5 removes Ecdsa::create() + if ($this->usePackageV4() && is_subclass_of($signer, Ecdsa::class)) { return $signer::create(); } return new $signer(); } + private function usePackageV4() + { + $version = InstalledVersions::getPrettyVersion('lcobucci/jwt'); + return version_compare($version, '5.0.0', '<'); + } + /** * {@inheritdoc} */