0

I was trying to make HybridAuth Social Login(version 2.6.0) work on this simple php site. Downloaded HybridAuth and installed it. Whenever I click the link to login to a social network (facebook) it redirects me to (MY_BASE_URL/index.php?hauth.start=Facebook&hauth.time) without showing any login window/error messages at all.

Here is the file for connexion:

$config ="../hybridauth/config.php";
require_once( "../hybridauth/Hybrid/Auth.php" ); 


try{$hybridauth = new Hybrid_Auth( $config );
  $provider = @ trim( strip_tags( $_GET["provider"] ) );
  $adapter = $hybridauth->authenticate( $provider );  
  $adapter = $hybridauth->getAdapter( $provider );
  $user_data = $adapter->getUserProfile();
  if($user_data)
  {  
     print_r($user_data);
  }  
  else  
  {            
     echo '*******   CRASH   *******';          
     exit;   
  }  
}
catch( Exception $e ){    

  switch( $e->getCode() ){   
    case 0 : echo "Unspecified error."; break;  
    case 1 : echo "Hybriauth configuration error."; break;  
    case 2 : echo "Provider not properly configured."; break;  
    case 3 : echo "Unknown or disabled provider."; break;  
    case 4 : echo "Missing provider application credentials."; break;  
    case 5 : echo "Authentication failed. "   
              . "The user has canceled the authentication or the provider refused the connection.";   
    case 6 : echo "User profile request failed. Most likely the user is not connected "  
              . "to the provider and he should to authenticate again.";   
           $adapter->logout();   
           break;  
    case 7 : echo "User not connected to the provider.";   
           $adapter->logout();   
           break;  
}   
echo "<b>Original error message:</b> " . $e->getMessage();  
    echo "<hr /><h3>Trace</h3> <pre>" . $e->getTraceAsString() . "</pre>";    
}

Here is the config file:

return
    array(
        "base_url" => "http://woonmako.com/hybridauth/index.php",
        "providers" => array(

            "Google" => array(
                "enabled" => true,
                "keys" => array("id" => "", "secret" => ""),
            ),
            "Facebook" => array(
                "enabled" => true,
                "keys" => array("id" => "*********", "secret" => "***********"),
                "trustForwarded" => false
            ),
            "Twitter" => array(
                "enabled" => true,
                "keys" => array("key" => "", "secret" => ""),
                "includeEmail" => false
            ),
        ),

        "debug_mode" => false,
        "debug_file" => "",

);

I would like to know how it's work and in which file I have to get user's information.

Poul Kruijt
  • 69,713
  • 12
  • 145
  • 149
Amadou Beye
  • 2,538
  • 3
  • 16
  • 37

2 Answers2

0

Hybrid_User_Profile Hybrid/User/Profile.php Hybrid_User_Profile

1.object represents the current logged in user profile. list of fields available in the normalized user profile structure used by HybridAuth. The

2.object is populated with as much information about the user as HybridAuth was able to pull from the given API or authentication provider.

Example

// try to authenticate the user with Twitter
$twitter_adapter = $hybridauth->authenticate( "Twitter" );

// get the user profile
$twitter_user_profile = $twitter_adapter->getUserProfile();

// debug the received user profile
print_r( $twitter_user_profile );

// echo the user profile page on twitter >> http://twitter.com/<username>
echo $twitter_user_profile->profileURL;

Properties of Hybrid_User_Profile Class

and more details you can get here

Santosh Ram Kunjir
  • 1,074
  • 1
  • 12
  • 23
0

I had the same problem just now and solved after a lot of search and test. In the end, you only miss the last part of "processing" the response.

Take a look at this thread: https://stackoverflow.com/a/31795036/6018431

You need to add a check like this:

if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done'])) {
    Hybrid_Endpoint::process();
}

Infact, when you say "I'm redirected in the page with hauth_start/hauth_done params in query string" in that point you need to check for the presence of that vars, and if found, call the process() static method.

I literally freaked out to find this simple line of code. I've never found or read in the documentation, but if you read about the Oauth2 flow, you'll be understand that "something has to be made for the final part of the flow".

Cheers

Community
  • 1
  • 1