I am trying to write a plugin for my website to connect with facebook using the HybridAuth classes.
I just tried following code
function authenticatewith( $provider ) {
ini_set('display_errors','on');
//includes
$config = dirname(__FILE__) . '/hybridauth-2.1.2/hybridauth/config.php';
require_once("hybridauth-2.1.2/hybridauth/Hybrid/Auth.php");
$provider_name = $provider;
//$config = $this->getconfig($id);
try {
// initialize Hybrid_Auth with a given file
$hybridauth = new Hybrid_Auth($config);
// try to authenticate with the selected provider
$adapter = $hybridauth->authenticate($provider_name);
// then grab the user profile
$user_profile = $adapter->getUserProfile();
}
catch( Exception $e ) {
echo "Error: please try again!";
echo "Original error message: " . $e->getMessage();
}
echo "User Details: ";
var_dump($user_profile);
}
When I call this function form the plugin class. In the browser it shows the following error:
You cannot access this page directly.
...and the URL in the address bar of the browser is something like this:
http://zyx.com/oinmonm/plugins/sociallogin/hybridauth-2.1.2/hybridauth/?hauth.start=Facebook&hauth.time=1415168326
After searching stackoverflow I found a similar question that describes about similar problem, but I have not been able to figure out how to apply the suggestions there to my code fix the issue:
You cannot access this page directly - HybridAuth Social Login
Most probably the problem is with the different domain names, as my website is running on two different domains.
How can I fix my code to prevent this issue?
More Details
I have a facebook link on www.bca.com(example) then when you click it goes to a controller.php file that will access the plugin that I am writing . Usually if I save a folder in the website like the plugin folder that is not accessible by www.bca.com instead its accessible by some other domain name .
What I am trying to say is that the session is starting in bca.com but the Hybridauth classes are saved in some other domain . And I think this is the reason the error is coming.
I tried to debug and found out the error is popping from following lines in Endpoint.php file
// Check if Hybrid_Auth session already exist
if (! $storage->config("CONFIG")) {
header("HTTP/1.0 404 Not Found");
die("You cannot access this page directly.");
}
I have been trying to fix this from last 3 days . But I am stuck at this point plz some one help me out. Thanks in advance