-
Notifications
You must be signed in to change notification settings - Fork 50
OAuth login often fails in new UI (4582) #3385
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
base: trunk
Are you sure you want to change the base?
OAuth login often fails in new UI (4582) #3385
Conversation
This change addresses the timing issue which often leads to failed login attempts
This condition returns true, even though the token is not valid anymore.
PayPal triggers multiple page redirects after completing the login popup. This commit introduces a new state handler that will halt duplicate requests until the first request is finished
sleep( 1 ); | ||
|
||
// Get the current URL. | ||
$current_url = add_query_arg( null, null ); |
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.
To be honest, I’m not a big fan of adding inline comments. I understand that they can make the code clearer, especially in this plugin where some logic is quite complex. However, in cases where the code is obvious like here, I would suggest not adding them. This isn't a strong opinion and open to discussion. Another point is that other devs aren’t adding them either, which leads to inconsistent styling.
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.
Thanks for working on this. I’ve raised a point we can discuss in another context, but it’s absolutely not something that would prevent me from approving this PR, although haven't tested locally.
Description
This PR refactores the OAuth process in two ways:
I) Solve timing issues between REST and redirect
The initial REST call only stores the auth_code and ID, without attempting to resolve them directly. This ensures that the REST call finishes very fast.
The following page reload fetches the code/id from the DB and performs the API requests which were initially handled in the Ajax call. This consolidates the full authentication logic to the same HTTP request.
II) Handling concurrent page loads
After finishing the login popup, PayPal often starts TWO page reloads. While the first (detached) request handles the authentication correctly, the second request (which happens in the browser) would previously run into a “token already used” situation and display the login screen again.
A new state was introduced to mark the token as “currently processing” (max lifetime 10 seconds). When any follow-up request encounter this “currently processing” state, they will pause for 1 second and do a simple page reload, waiting for the authentication request to complete.