Loading...
 
Features / Usability

Features / Usability


Re: Social Login unable to auto create user

posts: 400

Kaya,

One favor, was wondering if you could test this code. Please replace the entire function getFacebookAccessToken() starting around line 193 of lib/socialnetworkslib.php with the following and then see if the log in with facebook button is working appropriately, creating a new user. I'm just testing this for future versions as I believe it falls back automatically to a method that works. Please revert back to your original code after you're through testing. Many thanks!

function getFacebookAccessToken()
	{
		global $prefs;
		// try ZendOAuth
		$this->options['callbackUrl'] = $this->getURL();
		$this->options['requestTokenUrl'] = 'https://graph.facebook.com/' . $this->graphVersion . '/oauth/access_token';
		$consumer = new ZendOAuth\Consumer($this->options);
		$httpClient = TikiLib::lib('tiki')->get_http_client();
		$consumer->setHttpClient($httpClient);
		$customServiceParameters = [
			'client_id' => $prefs['socialnetworks_facebook_application_id'],
			'client_secret' => $prefs['socialnetworks_facebook_application_secr'],
			'redirect_uri' => $this->getURL(),
			'code' => $_REQUEST['code']
		];
		/** @var ZendOAuth\Token\Request $token */
		try {
			$token = $consumer->getRequestToken($customServiceParameters);
		} catch (Exception $e) {
			Feedback::error($e->getMessage());
			header("Location: tiki-index.php");
			die();
		}
		$resp = $token->getResponse();
		$ret = $resp->getContent();
		$json_decoded_ret = json_decode($ret, true);

		if (isset($json_decoded_ret['access_token']) || substr($ret, 0, 13) == 'access_token=') {
			if (isset($json_decoded_ret['access_token'])) {
				$access_token = $json_decoded_ret['access_token'];
			} else {
				$access_token = substr($ret, 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($json_decoded_ret['error']) || ! empty($curl_error)) {
				if (! empty($json_decoded_ret['error'])) {
					Feedback::error($json_decoded_ret['error']['type'] . ': ' . $json_decoded_ret['error']['message']);
				} else {
					Feedback::error($curl_error);
				}
			}
			return null;
		}
	}