I can login/auth the user with Hybridauth3 lib. Here is my code:
session_name("authSession");
session_start();
include 'hybridauth/src/autoload.php';
$config = [
'callback' => "https://***/loginRead.php",
'providers' => [
'Twitter' => [],"includeEmail" => true],
'Google' => [],
'Facebook' => []
],
];
$authName = "Facebook";
if(isset($_REQUEST['provider'])){
$provider = strtolower($_REQUEST['provider']);
switch ($provider) {
case 'google':
$authName = "Google";
break;
case 'facebook':
$authName = "Facebook";
break;
case 'twitter':
$authName = "Twitter";
break;
}
$_SESSION['provider'] = $authName;
$hybridauth = new Hybridauth\Hybridauth( $config );
$adapter = $hybridauth->getAdapter($authName);
$user = $adapter->authenticate();
$userProfile = $adapter->getUserProfile();
}
// this part is for this callback https://***/loginRead.php from config
if(isset($_SESSION['HYBRIDAUTH::STORAGE']) && count($_SESSION['HYBRIDAUTH::STORAGE'])>=1){
$provider = $_SESSION['provider'];
$hybridauth = new Hybridauth\Hybridauth( $config );
$adapter = $hybridauth->getAdapter($provider);
$user = $adapter->authenticate();
$userProfile = $adapter->getUserProfile();
}
if(isset($_GET['loginExit'])){
$adapter->disconnect();
$hybridauth->disconnectAllAdapters();
session_destroy();
header("Location:test.php");
exit();
}
echo '<img src="'.$userProfile->photoURL.'"><br>';
echo $userProfile->identifier.'<br>';
echo '<a href="?loginExit">Exit</a>';
But I am pretty sure that I am not using it right. As I am saving the provider in session for the second redirect, but there must be way to get the provider name with Hybridauth api or maybe there is no need to do that? How to auth the user with [HYBRIDAUTH::STORAGE] without knowing the privider name? Is there any good 100% working example for the 3 version or etc? Thanks