XF 2.0 Google account integration problem with connected_account.php

Carlo

Member
I am trying to integrate Google account login. I followed the steps outlined in https://xenforo.com/help/google-integration/

So far everything went well. In the part where I have to enter Authorized redirect URIs, if I enter https://www.mydomain.com, it causes error when testing. I get Error 400 "Error: redirect_uri_mismatch" The redirect URI in the request, https://www.mydomain.com/connected_account.php, does not match the ones authorized for the OAuth client.

To fix the error, I enter https://www.mydomain.com/connected_account.php in Authorized redirect URIs. This seems to work as it allows the test to continue and ask for my Google login. However after I complete my Google sign-in, the connected_account.php file gets downloaded instead of being redirected back to my site. Can anyone tell me what's wrong? I managed to integrate Facebook without issues.
 
I managed to connect LinkedIn by entering https://www.mydomain.com/connected_account.php into OAuth 2.0 Authorized Redirect URLs. And it is correctly redirecting back to my site after I sign in using LinkedIn account.

Google integration is still an issue because instead of redirecting, it wants me to download the connected_account.php file. So I downloaded it and when opened, it contains the plain text:

An error occurred while connecting with Google. Please try again later.

Any ideas?
 
Ok I managed to solve the file downloading issue. It's because of the code part:

Code:
if (!$token = $handler->requestProviderToken($storageState, $request, $error, $connectedAccountRequest['test']))
{
        $response
            ->body($error)
            ->send($request);
    exit;
}

found in connected_account.php. It seems that my server (nginx + php-fpm) cannot properly redirect to my site if the Google window is active and the response is sent. I wrote a workaround to force it to redirect so it's no longer downloading the php file but instead shows the error message.

So still remaining issue is the "An error occurred while connecting with Google. Please try again later." error. I have set up all URLs correctly in the Google console but still doesn't work.

Anyone who managed to integrate Google in XF 2, can you please share the steps you have taken. Thanks.
 
You need setup both SSL and Non-SSL with www and non-www URL in Authorized JavaScript origins and Authorized redirect URIs.

View attachment 169190
That's the orginal error I encountered. I fixed it by entering under" Authorized redirect URIs https://www.mydomain.com/connected_account.php. But then I got the error "An error occurred while connecting with Google. Please try again later."

I implemented both of these suggestions and then the error disappeared.
Google login now works flawlessly it seems. So thanks fellas for the helpful info. Cheers.

J.
 
Top Bottom