-
Notifications
You must be signed in to change notification settings - Fork 8
OAuth: Fix Refresh Token Scheduled Time #840
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
Conversation
WordPress Playground🚀 Your PR has been built and is ready for testing in WordPress Playground! |
WordPress Playground🚀 Your PR has been built and is ready for testing in WordPress Playground! |
noelherrick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not completely understanding this: why would we schedule a cron job vs. immediately refreshing if the expiration is already passed? If created_at + expired_in is not the actual expiration time, what is?
There's an elevated number of 401 unauthorized requests to the API. Whilst the WordPress Libraries check if an API response is a 401 (and if so, refreshes the token), I'm being asked for a more proactive approach here, hence scheduling a cron event to automatically perform this step when we know the token expires, rather than waiting for the next API call to then refresh the token.
|
|
@n7studios I understand that the expiration could be in the past, but why wouldn't we just immediately refresh the token vs. schedule a job when that's true? |
The job is scheduled to refresh the token on its expiry, so the sites always have a valid access token. Whilst the WordPress Libraries will check if the API response is a 401 (and if so, refresh the token), lower traffic sites won't call the API regularly. Relying on this check alone might be a cause of the elevated 401 issues that I'm being asked to provide a more proactive approach towards. If this PR doesn't cut it, not an issue - we can go ahead and close. |
|
Tim, I totally get what you're trying to do (schedule a cron job to renew creds on low traffic sites) and the bug we're fixing (scheduled dates for those jobs are in the past) but I get the sense there is something we're missing. Are you saying that when you hit the V4 endpoint, the created_at + expired_in can be in the past? Is this actually a time zone bug? |
No.
Example:
Using |
noelherrick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@n7studios Thanks for your patience - the reinstall scenario was what I was missing (and the fact that expires_in changes based on the time of the request)
Summary
#839 incorrectly added the
expires_inresponse parameter value to the token'screated_attime, instead of the current timestamp (time()), resulting in the WordPress cron event to refresh the token being scheduled in the past:Tests did not detect this as tests mock making a call to refresh an 'expired' access token, setting the API's
created_atresponse parameter as the current date and time, instead of when the access token was created.This PR resolves by:
refresh_tokenmethodTesting
Existing tests pass.
Checklist