Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ You can find and compare releases at the [GitHub release page](https://github.co
## [Unreleased]
### Fixed
- Fixed the return type of getMinutesUntilExpired in BlackList, which returned a float instead of an int when using Carbon v2.
- Fixed PHPStan issue in JWTGenerateSecretCommand by ensuring displayKey($key); is called before returning, avoiding returning a void method.
- Fixed missing return true; statements in validatePayload() and validateRefresh() methods of Expiration.php, IssuedAt.php, and NotBefore.php to resolve PHPStan errors.
- Fixed PHPStan error related to new static() by making the constructor final in Collection.php.


## [2.8.0] 2025-02-11
Please see (https://github.com/PHP-Open-Source-Saver/jwt-auth/releases/tag/2.8.0)
Expand Down
30 changes: 0 additions & 30 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Claims/Collection.php

-
message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\Expiration\\:\\:validatePayload\\(\\) should return bool but return statement is missing\\.$#"
count: 1
path: src/Claims/Expiration.php

-
message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\IssuedAt\\:\\:validatePayload\\(\\) should return bool but return statement is missing\\.$#"
count: 1
path: src/Claims/IssuedAt.php

-
message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\IssuedAt\\:\\:validateRefresh\\(\\) should return bool but return statement is missing\\.$#"
count: 1
path: src/Claims/IssuedAt.php

-
message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\NotBefore\\:\\:validatePayload\\(\\) should return bool but return statement is missing\\.$#"
count: 1
path: src/Claims/NotBefore.php

-
message: "#^Result of method PHPOpenSourceSaver\\\\JWTAuth\\\\Console\\\\JWTGenerateSecretCommand\\:\\:displayKey\\(\\) \\(void\\) is used\\.$#"
count: 1
path: src/Console/JWTGenerateSecretCommand.php

-
message: "#^Class Laravel\\\\Octane\\\\Events\\\\RequestReceived not found\\.$#"
count: 1
Expand Down
12 changes: 11 additions & 1 deletion src/Claims/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,17 @@ public function validate($context = 'payload')
*/
public function hasAllClaims($claims)
{
return count($claims) && (new static($claims))->diff($this->keys())->isEmpty();
if (!count($claims)) {
return false;
}

foreach ($claims as $claim) {
if (!$this->has($claim)) {
return false;
}
}

return true;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Claims/Expiration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ public function validatePayload()
if ($this->isPast($this->getValue())) {
throw new TokenExpiredException('Token has expired');
}

return true;
}
}
4 changes: 4 additions & 0 deletions src/Claims/IssuedAt.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ public function validatePayload()
if ($this->isFuture($this->getValue())) {
throw new TokenInvalidException('Issued At (iat) timestamp cannot be in the future');
}

return true;
}

public function validateRefresh($refreshTTL)
{
if ($this->isPast($this->getValue() + $refreshTTL * 60)) {
throw new TokenExpiredException('Token has expired and can no longer be refreshed');
}

return true;
}
}
2 changes: 2 additions & 0 deletions src/Claims/NotBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ public function validatePayload()
if ($this->isFuture($this->getValue())) {
throw new TokenInvalidException('Not Before (nbf) timestamp cannot be in the future');
}

return true;
}
}
4 changes: 3 additions & 1 deletion src/Console/JWTGenerateSecretCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public function handle()
}

if (!$this->envFileExists()) {
return $this->displayKey($key);
$this->displayKey($key);

return;
}

$updated = $this->updateEnvEntry('JWT_SECRET', $key, function () {
Expand Down
Loading