我可以使用Hybridauth3 lib登錄/授權用戶。 這裏是我的代碼:如何使用Hybridauth 3登錄/註銷?
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>';
但我敢肯定,我沒有使用它的權利。 由於我在第二次重定向的會話中保存提供程序,但是必須有辦法使用Hybridauth API獲取提供程序名稱,或者可能沒有必要這樣做?如何用[HYBRIDAUTH :: STORAGE]授權用戶而不知道私有名稱? 3版本還有什麼好的100%實例嗎?謝謝
我明白的是;你需要在你的url鏈接中有'$ authName'嗎? –
@AnarBayramov我需要一個很好的示例/如何使用Hybridauth 3的解釋。我可以找到任何好的例子,只是如何驗證,這就是全部。我正在更新我的問題。給我一分鐘 – SERG
https://github.com/rgnevashev/hybridauth3/tree/master/example? –