Skip to content

Commit

Permalink
chore(deps): update lcobucci/jwt to include 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqi committed Nov 29, 2024
1 parent 51620eb commit a9115f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
26 changes: 17 additions & 9 deletions src/Providers/JWT/Lcobucci.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Tymon\JWTAuth\Providers\JWT;

use Composer\InstalledVersions;
use DateTimeImmutable;
use DateTimeInterface;
use Exception;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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}
*/
Expand Down

0 comments on commit a9115f6

Please sign in to comment.