簡體   English   中英

HybridAuth:重定向后如何獲取用戶的信息

[英]HybridAuth: How to get users's info after redirection

我試圖使HybridAuth Social Login(版本2.6.0)在此簡單的php網站上工作。 下載並安裝HybridAuth。 每當我單擊鏈接登錄到社交網絡(facebook)時,它都會將我重定向到(MY_BASE_URL / index.php?hauth.start = Facebook&hauth.time),而不顯示任何登錄窗口/錯誤消息。

這是連接文件:

$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>";    
}

這是配置文件:

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" => "",

);

我想知道它是如何工作的,我必須在哪個文件中獲取用戶信息。

Hybrid_User_Profile Hybrid / User / Profile.php Hybrid_User_Profile

1.object代表當前登錄的用戶配置文件。 HybridAuth使用的規范化用戶配置文件結構中可用的字段列表。

2.object填充了與HybridAuth能夠從給定API或身份驗證提供程序中提取的用戶信息一樣多的信息。

// 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;

Hybrid_User_Profile類的屬性

和更多的細節,你可以在這里

我剛才遇到了同樣的問題,經過大量的搜索和測試后才解決。 最后,您僅會錯過“處理”響應的最后一部分。

看看這個線程: https : //stackoverflow.com/a/31795036/6018431

您需要添加這樣的支票:

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

實際上,當您說“我在頁面中使用查詢字符串中的hauth_start / hauth_done參數重定向”時,您需要檢查該var是否存在,如果找到,則調用process()靜態方法。

我真的很害怕找到這行簡單的代碼。 我從未在文檔中找到或閱讀過該文檔,但是,如果您閱讀有關Oauth2流的信息,您將會理解“必須為該流的最后一部分做一些事情”。

干杯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM