title: Facebook Login using HybridAuth showing error You cannot access this page directly
body: <p>I am trying to write a plugin for my website to connect with facebook using the HybridAuth
  classes. </p>
  
  <p>I just tried following code </p>
  
  <pre><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-&gt;getconfig($id);
      try {
          // initialize Hybrid_Auth with a given file
          $hybridauth = new Hybrid_Auth($config);
  
          // try to authenticate with the selected provider
          $adapter = $hybridauth-&gt;authenticate($provider_name);
  
          // then grab the user profile 
          $user_profile = $adapter-&gt;getUserProfile();
      }
      catch( Exception $e ) {
          echo "Error: please try again!";
          echo "Original error message: " . $e-&gt;getMessage();
      }
  
      echo "User Details: ";
      var_dump($user_profile);
  }
  </code></pre>
  
  <p>When I call this function form the plugin class. In the browser it shows the following error:</p>
  
  <blockquote>
    <p>You cannot access this page directly.</p>
  </blockquote>
  
  <p>...and the URL in the address bar of the browser is something like this:</p>
  
  <blockquote>
    <p><a href="http://zyx.com/oinmonm/plugins/sociallogin/hybridauth-2.1.2/hybridauth/?hauth.start=Facebook&amp;hauth.time=1415168326" rel="nofollow noreferrer">http://zyx.com/oinmonm/plugins/sociallogin/hybridauth-2.1.2/hybridauth/?hauth.start=Facebook&amp;hauth.time=1415168326</a></p>
  </blockquote>
  
  <p>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:</p>
  
  <p><a href="https://stackoverflow.com/questions/18655472/you-cannot-access-this-page-directly-hybridauth-social-login">You cannot access this page directly - HybridAuth Social Login</a></p>
  
  <p>Most probably the problem is with the different domain names, as my website is running on two different domains.</p>
  
  <p>How can I fix my code to prevent this issue?</p>
  
  <p><strong>More Details</strong></p>
  
  <p>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 .</p>
  
  <p>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. </p>
  
  <p>I tried to debug and found out the error is popping from  following lines  in Endpoint.php file</p>
  
  <pre><code>// Check if Hybrid_Auth session already exist
  if (! $storage-&gt;config("CONFIG")) { 
      header("HTTP/1.0 404 Not Found");
      die("You cannot access this page directly.");
  }
  </code></pre>
  
  <p>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</p>