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 from storage should expire but hasExpired always returns false #942

Open
edsonhoraciojunior opened this issue Mar 10, 2022 · 1 comment

Comments

@edsonhoraciojunior
Copy link

edsonhoraciojunior commented Mar 10, 2022

I'm using OAuth 2 with Forge Autodesk, they usually return tokens with expires_in: 3599.
If I get a token from storage and run

$token = new AccessToken($token);
if ($token->hasExpired()) {
    $this->refreshToken($token);
}

$accessToken->hasExpired() always return false, because on the construct the expiration date is calculated with timeNow + expires_in.
With this logic, the token will never expire, which is incorrect.

  1. Is this logic incorrect?
  2. Am I using OAuth wrong? Am I expected to always refresh the token before using it for the second time, even if it didn't expire?
@edsonhoraciojunior
Copy link
Author

edsonhoraciojunior commented Mar 10, 2022

Me and my buddies were checking this situation and we found out that instead of saving the token->getValues() (which has expires_in) to the DB, we should save the result of jsonSerialize(), which calculates the expires with the correct timestamp in seconds.
I think we can improve the documentation by adding this info, making it explicit, what do you think?

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

1 participant