diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-11-10 10:46:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 10:46:04 +0100 |
commit | 302662797cb5e8ac6579a99297ceae301f7927a6 (patch) | |
tree | 67f493a1cc6d3691742946f1d7e512bffe41e02f /application/api/ApiUtils.php | |
parent | c94c32d1a3e86a479cb2582eadc668a5bb476fc6 (diff) | |
parent | 2f4df753041088d788d1923692a7d530167a6840 (diff) | |
download | Shaarli-302662797cb5e8ac6579a99297ceae301f7927a6.tar.gz Shaarli-302662797cb5e8ac6579a99297ceae301f7927a6.tar.zst Shaarli-302662797cb5e8ac6579a99297ceae301f7927a6.zip |
Merge pull request #1635 from ArthurHoaro/feature/phpcs
Diffstat (limited to 'application/api/ApiUtils.php')
-rw-r--r-- | application/api/ApiUtils.php | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php index eb1ca9bc..05a2840a 100644 --- a/application/api/ApiUtils.php +++ b/application/api/ApiUtils.php | |||
@@ -1,4 +1,5 @@ | |||
1 | <?php | 1 | <?php |
2 | |||
2 | namespace Shaarli\Api; | 3 | namespace Shaarli\Api; |
3 | 4 | ||
4 | use Shaarli\Api\Exceptions\ApiAuthorizationException; | 5 | use Shaarli\Api\Exceptions\ApiAuthorizationException; |
@@ -27,7 +28,7 @@ class ApiUtils | |||
27 | throw new ApiAuthorizationException('Malformed JWT token'); | 28 | throw new ApiAuthorizationException('Malformed JWT token'); |
28 | } | 29 | } |
29 | 30 | ||
30 | $genSign = Base64Url::encode(hash_hmac('sha512', $parts[0] .'.'. $parts[1], $secret, true)); | 31 | $genSign = Base64Url::encode(hash_hmac('sha512', $parts[0] . '.' . $parts[1], $secret, true)); |
31 | if ($parts[2] != $genSign) { | 32 | if ($parts[2] != $genSign) { |
32 | throw new ApiAuthorizationException('Invalid JWT signature'); | 33 | throw new ApiAuthorizationException('Invalid JWT signature'); |
33 | } | 34 | } |
@@ -42,7 +43,8 @@ class ApiUtils | |||
42 | throw new ApiAuthorizationException('Invalid JWT payload'); | 43 | throw new ApiAuthorizationException('Invalid JWT payload'); |
43 | } | 44 | } |
44 | 45 | ||
45 | if (empty($payload->iat) | 46 | if ( |
47 | empty($payload->iat) | ||
46 | || $payload->iat > time() | 48 | || $payload->iat > time() |
47 | || time() - $payload->iat > ApiMiddleware::$TOKEN_DURATION | 49 | || time() - $payload->iat > ApiMiddleware::$TOKEN_DURATION |
48 | ) { | 50 | ) { |