502 Bad Gateway when using Auth0 PHP SDK for basic social sign in integration

I’m attempting to use Auth0’s PHP SDK to create a very basic social sign in integration (i.e. a button which says “Sign in using your Google account”). Note: I don’t want to use Auth0’s Universal Login page; I want to directly send the user to the Google/Facebook/etc. auth page and then back to my own site.

I have followed the quick start guide, but have supplied a connection parameter to the login() since I want to use Google as the provider.

This generates login URLs fine, however when I return to the callback URL I receive a 502 Bad Gateway error from nginx. Refreshing the page gives a more helpful exception: Code exchange was unsuccessful; network error resulted in unfulfilled request.

Here is briefly what my code looks like:

// index.php

$session = $auth0->getCredentials();

if ($session === null) {
	// The user isn't logged in.
	echo '<p>Please <a href="/login.php">log in</a>.</p>';
	return;
}

// The user is logged in.
echo '<pre>';
print_r($session->user);
echo '</pre>';

// login.php

header("Location: " . $auth0->login(ROUTE_URL_CALLBACK, ['connection' => "google-oauth2"]));

// callback.php

$auth0->exchange(ROUTE_URL_CALLBACK);
header("Location: " . ROUTE_URL_INDEX);

Note that I have been able to get the callback page working when I use the much more verbose code from the authentication API example guide - but I would like to know why it doesn’t work using the much more elegant and succinct “standard” code above.

Hey there!

In order to handle that most effectively can I encourage you to raise it in a form of GitHub issue in the SDK repo here:

so we can directly discuss that with the repo maintainers? Once you have a link to it please share it here so we can ping them. Thank you!