Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token sometimes re-used too close to expiration. #24

Closed
alexander-aleman opened this issue Nov 23, 2022 · 1 comment
Closed

Token sometimes re-used too close to expiration. #24

alexander-aleman opened this issue Nov 23, 2022 · 1 comment

Comments

@alexander-aleman
Copy link

Hi,

I'm running into an issue that a token is re-used very close to the expiration of the token, which then cause a not-authorized response from the API.

I believe this is caused by the following line of code:

$expiration = new \DateTime('now + ' . $expiresIn . ' seconds');

or you could argue that this should be handled in the validation part:

return (new \DateTime()) < $this->expiration;

In my case I have solved this for now by adding a small safety margin:

--- a/src/Manager/JwtManager.php	2022-11-23 10:01:15.148041661 +0100
+++ b/src/Manager/JwtManager.php	2022-11-23 10:00:33.247774501 +0100
@@ -132,7 +132,7 @@
         }

         if ($expiresIn) {
-            $expiration = new \DateTime('now + ' . $expiresIn . ' seconds');
+            $expiration = new \DateTime('now + ' . ((int)($expiresIn * 0.9)) . ' seconds');
         } elseif (count($jwtParts = explode('.', $tokenValue)) === 3
             && is_array($payload = json_decode(base64_decode($jwtParts[1]), true))
             // https://tools.ietf.org/html/rfc7519.html#section-4.1.4

Perhaps you could think of a more elegant solution.

@michielkalle
Copy link
Contributor

michielkalle commented Apr 20, 2023

I agree, I have the same issue.

Example:

return (new \DateTime('now + 1 seconds')) < $this->expiration;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants