Loading...
 
Features / Usability

Features / Usability


Re: Social Login unable to auto create user

posts: 400

Haha! I already fix bugs for no pay, now to pay to fix bugs, that would be a first!

In all seriousness, I appreciate your help as the only user I know with these types of errors that I am unable to recreate. I have worked further to make the code more error proof (hopefully!) and was hoping you would be willing to perform one more test.

If so, please replace the entire function getFacebookAccessToken() (starting around line 193 in lib/socialnetworkslib.php) with the following and try to log in using facebook. Please let me know if the login is successful and any messages you get.

Many thanks!
lindon

function getFacebookAccessToken()
	{
		global $prefs;

		// set up http client to make request
		$client = new \Zend\Http\Client();
		$client->setUri('https://graph.facebook.com/' . $this->graphVersion . '/oauth/access_token');
		$client->setArgSeparator('&');
		$client->setParameterGet([
			'redirect_uri' => $this->getURL() . '?request_facebook',
			'client_id'  => $prefs['socialnetworks_facebook_application_id'],
			'client_secret' => $prefs['socialnetworks_facebook_application_secr'],
			'code' => $_REQUEST['code']
		]);
		// first try request with default socket adapter
		$response = $client->send();
		$body = $response->getBody();
		$decodedBody = json_decode($body);
		Feedback::success(tr('I am using sockets!'));
		if (! $response->isSuccess() || ! isset($decodedBody->access_token)) {
			//if sockets don't work try cURL adapter
			$client->setAdapter(\Zend\Http\Client\Adapter\Curl::class);
			$response = $client->send();
			$body = $response->getBody();
			$decodedBody = json_decode($body);
			Feedback::success(tr('I am using cURL!'));
		}


		if (isset($decodedBody->access_token) || substr($body, 0, 13) == 'access_token=') {
			if (isset($decodedBody->access_token)) {
				$access_token = $decodedBody->access_token;
			} else {
				$access_token = substr($body, 13);
				if ($endoftoken = strpos($access_token, '&')) {
					// Returned string may have other var like expiry
					$access_token = substr($access_token, 0, $endoftoken);
				}
			}

			return $access_token;
		} else {
			if (! empty($decodedBody->error)) {
				Feedback::error($decodedBody->error->type . ': ' . $decodedBody->error->message);
			} else {
				Feedback::error(tr('Facebook feed data not retrieved'));
			}
			return null;
		}
	}