【问题标题】:HybridAuth: How to get users's info after redirectionHybridAuth:重定向后如何获取用户信息
【发布时间】:2016-07-23 05:24:04
【问题描述】:

我试图让 HybridAuth 社交登录(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" => "",

);

我想知道它是如何工作的以及我必须在哪个文件中获取用户信息。

【问题讨论】:

    标签: php hybridauth


    【解决方案1】:

    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;
    

    更多详情您可以获取here

    【讨论】:

      【解决方案2】:

      我刚才遇到了同样的问题,经过大量搜索和测试后解决了。 最后,您只会错过“处理”响应的最后一部分。

      看看这个线程: https://stackoverflow.com/a/31795036/6018431

      您需要添加这样的检查:

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

      事实上,当您说“我在查询字符串中使用 hauth_start/hauth_done 参数重定向页面”时,您需要检查该变量是否存在,如果找到,请调用 process() 静态方法.

      我真的吓坏了,找到了这行简单的代码。 我从未在文档中找到或阅读过,但如果您阅读过有关 Oauth2 流程的信息,您就会明白“必须为流程的最后部分做一些事情”。

      干杯

      【讨论】:

        猜你喜欢
        • 2022-01-16
        • 2020-04-23
        • 2018-02-09
        • 2014-02-05
        • 2011-01-24
        • 1970-01-01
        • 2020-10-25
        • 2021-09-27
        • 2014-04-26
        相关资源
        最近更新 更多