Topic-icon Yahoo & VK Logins not working

Active Subscriptions:

None
9 years 3 months ago - 9 years 3 months ago #60918 by Dayo
Replied by Dayo on topic Yahoo & VK Logins not working
Hello,

Been rooting and debugging further and I have come up with something that seems to suggest there is a real issue. Basically, there seems to be a never ending loop in calls to user authenticate and this seems to be the reason why there is the 504 Timeout Error.

In summary the flow for Yahoo, Google, VK etc is:
1. User clicks on JFBConnect Button
2. This calls "login" function in "/components/com_jfbconnect/controllers/authenticate.php"
3. This function includes a call to "$provider->client->authenticate();" <- NOTE THIS
4. This leads to the "authenticate" function in "/components/com_jfbconnect/libraries/authentication/oauth2base.php"
5. This function includes a call to "$response = $this->http->post($this->getOption('tokenurl'), $data);"
6. The "$data" parameter in the call above requires the provider to return to the "callback" function in "/components/com_jfbconnect/controllers/authenticate.php"
7. This function includes another call to "$provider->client->authenticate();" <- NOTE THIS
8. The flow therefore returns to STEP 4 and loops forever between STEPS 4 and 7 until the server times out.

There is something not right in this and it seems the only reason Twitter works is because it does not seem to include return to the "callback" function and therefore does not get stuck in the endless loop.

All the responses I have gotten so far have been telling me it is my server or host or similar and I will appreciate an actual serious look at the issue.
I am happy to work with the developer(s) to work through things and figure out the real root cause; which to me is a question of why the "callback" is calling "$provider->client->authenticate();" again given that this is the call that leads to this callback function in the first place and which results in the endless loop.

Is someone who actually wrote this code available? Perhaps this can be dug into off the forum.
Last edit: 9 years 3 months ago by Dayo.
The topic has been locked.
Support Specialist
9 years 3 months ago #60927 by alzander
Dayo,
The OAuth2 code is actually originally from Joomla itself. You can find an almost identical file in /libraries/joomla/oauth2/client.php. We copied it so we could use the same file in Joomla 2.5 and 3.x as that file is only in 3.x. That function is near-identical between the 2 files and it definitely works.

As for who implemented that code in JFBConnect, it's me. The part your missing is that the first line in the authenticate function checks if a 'code' parameter is set. On the first call above, it definitely won't be as the round trip to VK or Yahoo hasn't happened yet. So, the line at the bottom like below should be called:
$this->application->redirect($this->createUrl());
That statement should always be called and the false should never be triggered because we force the sendhenders value to always be set.

So, step 3 calls authentication which redirects the user to VK or Yahoo or wherever to actually enter their credentials. Then, they should return to your site with a 'code' which is then posted back to that social network to get an actual authentication token. That's OAuth2 and yeah it's confusing, but it definitely works on many sites and in our automated tests suites we run against each social network before release.

Since your debugging code, here's what I'd recommend:
* In JFBConnect -> Configuration -> Facebook, set "Show 'Login Credentials' in popup" to 'No'. That will skip the popup flow for JFBConnect and use the same OAuth2 flow as the other networks. Knowing if that works helps narrow things down further.
* If you aren't already logged into those networks, when you click login, are you sent to enter your credentials properly? I believe so, and think you already answered this, but couldn't find it by skimming above.
* In the authenticate function, do a print_r($data) and exit after the first if statement. See if a code is ever printed as well as if that block is ever entered. If not, it means the code is never coming back from the network (or being stripped out by something on your site somewhere along the way).
* The 'code' should be in the URL. If you're using the browser's "Network" tab, you should see the looping requests and there should be a code= parameter in the URL. It should match the print statement above.

I hope that helps narrow some things down. We'll gladly keep helping diagnose things however we can.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
9 years 3 months ago #60978 by Dayo
Replied by Dayo on topic Yahoo & VK Logins not working
Thanks for the insights Alex,

I did see what you said about the check for "code" such that my Step 3 would actually be a call to "createUrl" after I posted but couldn't get back in time to fix my post. Mea Culpa!
A summary now is:
1. The "code" param is returned after the first call to authenticate.login and "createUrl"
2. Twitter works. fast, no issues.
3. Facebook works (slow) using the popup flow or otherwise.
4. Google, Yahoo etc all timeout.

From what I can see now, everything works until this line in oauth2base.php and this is where the timeout occurs:
$response = $this->http->post($this->getOption('tokenurl'), $data);
The topic has been locked.
Active Subscriptions:

None
9 years 3 months ago - 9 years 3 months ago #60984 by Dayo
Replied by Dayo on topic Yahoo & VK Logins not working
Found a partial solution.

In /components/com_jfbconnect/libraries/authentication/oauth2base.php, changing:
$this->http = isset($http) ? $http : new JHttp($this->options);

... to
$this->http = isset($http) ? $http : JHttpFactory::getHttp();

... results in Google working consistently. Extremely slow, but works consistently. Giving up on Yahoo, VK etc as a lost cause.

So summary at this point is:
1. Twitter - works. Fast, no issues.
2. Facebook - works (Very Slow: ~ 30 seconds from click to completion).
3. Google - works (Excruciatingly Slow: ~ 45 seconds or more from click to completion).
4. Yahoo, VK - all timeout.

Now need to figure out how to have a popup for Google like the Facebook one, maybe even add a pseudo percentage countdown to both, as I fear most users will bail out rather than wait a minute just to log in to a website ... I know I would!
Last edit: 9 years 3 months ago by Dayo.
The topic has been locked.
Active Subscriptions:

None
9 years 3 months ago #60986 by Dayo
Replied by Dayo on topic Yahoo & VK Logins not working
Implemented the progress bar which makes the wait easier to bear.
Also implemented for the facebook popup.
The topic has been locked.
Support Specialist
9 years 3 months ago #61003 by alzander
Sorry for the delayed response. Switching the http client shouldn't really matter, but glad it helps some.. What I'd recommend from here is exiting right before that line and getting the data that's about to be sent, like:
print_r($data);
exit;

Then, try to use cURL from the command line of your server to see how long the transaction takes with a command like (for Google):
curl --data "grant_type=refresh_token&refresh_toke=XXXX&client_id=YYYYY&client_secret=ZZZZZ" https://accounts.google.com/o/oauth2/token
See how long that takes. That's directly from your server and outside of Joomla so it will help narrow things down a bit further.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
9 years 3 months ago #61047 by Dayo
Replied by Dayo on topic Yahoo & VK Logins not working
Hi Alex,

I got what you were pointing to there so I took a close hard look at my server setup and noticed that the timeout always happened while waiting for the IPv6 response from the affected providers. I therefore changed the server DNS settings to continue to check for both IPv4 and IPv6 addresses but to try IPv4 first over the previous setup that tried IPv6 first (if it existed).

Problem solved with this change.

Many thanks to you and to Mel for your help.
The topic has been locked.
Support Specialist
9 years 3 months ago #61053 by mel
Replied by mel on topic Yahoo & VK Logins not working
I'm glad Alex's last suggestions helped and you were able to resolve the issue. Let us know if you run into any other strange/incorrect behavior.

-Melissa
The topic has been locked.