Re: Social Login unable to auto create user
This is what I've got:
Copy to clipboard
/** * Old tiki way of getting access_token using socket. Some say it faster than curl. Maybe we * need to move it to hybridauth as an alternative to curl, like guzzle? * * @return bool|string|null * @throws Exception */ 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; } } function getFacebookUserProfile($access_token) { global $prefs; $fields = ['id', 'name', 'first_name', 'last_name']; if ($prefs['socialnetworks_facebook_email'] == 'y') { $fields[] = 'email'; } $resp = $this->facebookGraph('', 'me', ['fields' => implode(',', $fields),'access_token' => $access_token], false, 'GET'); $fb_profile = json_decode($resp); return $fb_profile; }
I get an error message:
Copy to clipboard
Error Could not retrieve a valid Token response from Token URL: {"error":{"message":"Can't load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.","type":"OAuthException","code":191,"fbtrace_id":"HwYSLpDM2pj"}}