PHP HybridAuth社交登录根本不起作用.重定向到? hath .start=Facebook& hath .t


PHP HybridAuth social signin not working at all. Redirecting to ?hauth.start=Facebook&hauth.time

我试图使HybridAuth社会登录工作在这个简单的php网站。下载并安装HybridAuth。然后发现即使是示例也不能用于社交登录(在远程服务器上也尝试过)。

正常的signin_signup示例可以正常工作。但是,每当我点击链接登录到一个社交网络(即facebook,twitter),它重定向到(MY_BASE_URL/index.php? hath .start= facebook & hath .time),没有显示任何登录窗口/错误信息。

我已经仔细阅读了这里发布的文档和其他解决方案。调整我的config.php有一个基本的url,如http://example.com/index.php。但它就是没有回应。我是不是漏掉了什么?我已经花了两天的时间了。

这里是config.php

return 
    array(
        "base_url" => "http://example.com/index.php", 
        "providers" => array ( 
            // openid providers
            "OpenID" => array (
                "enabled" => false
            ),
            "AOL"  => array ( 
                "enabled" => false 
            ),
            "Yahoo" => array ( 
                "enabled" => false,
                "keys"    => array ( "id" => "", "secret" => "" )
            ),
            "Google" => array ( 
                "enabled" => true,
                "keys"    => array ( "id" => "", "secret" => "" )
            ),
            "Facebook" => array ( 
                "enabled" => true,
                "keys"    => array ( "id" => "xxxxxxxxx", "secret" => "xxxxxxx" )
            ),
            "Twitter" => array ( 
                "enabled" => true,
                "keys"    => array ( "key" => "xxxxxxxx", "secret" => "xxxxxxxx" ) 
            ),
            // windows live
            "Live" => array ( 
                "enabled" => false,
                "keys"    => array ( "id" => "", "secret" => "" ) 
            ),
            "MySpace" => array ( 
                "enabled" => false,
                "keys"    => array ( "key" => "", "secret" => "" ) 
            ),
            "LinkedIn" => array ( 
                "enabled" => true,
                "keys"    => array ( "key" => "xxxxxxxx", "secret" => "xxxxxxx" ) 
            ),
            "Foursquare" => array (
                "enabled" => false,
                "keys"    => array ( "id" => "", "secret" => "" ) 
            ),
        ),
        // if you want to enable logging, set 'debug_mode' to true  then provide a writable file by the web server on "debug_file"
        "debug_mode" => false,
        "debug_file" => ""
    );

有人能帮帮我吗?在网上搜索了很长时间后,我有一种感觉,它根本就不太好用。如果是这样的话,有人能指出一个更好的替代开源/免费社交登录库吗?

对于tintinboss自己的回答,我发现我也需要检查hauth_done(这是一个测试Facebook的例子):

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

这终于使它工作-谢谢你tintinboss有用的答案!

好了,我自己解决了。

如前所述,文档确实不太好。对于那些将来想要集成这些代码的人来说,这是一个解决方案

首先,你必须在config.php 中这样创建baseurl
"base_url" => "http://yoursite.com/subdomain/index.php", OR
"base_url" => "http://yoursite.com/index.php",

注意,我没有使用www。不知道为什么,但是它不能用www.

棘手的是,你需要把它包含在index。php文件

require_once( "PATH_TO_HYBRID/Auth.php" );
require_once( "PATH_TO_HYBRID/Endpoint.php" ); 
if (isset($_REQUEST['hauth_start']))
        {
            Hybrid_Endpoint::process();
        }

端点进程是使您重定向到一个空白页面,如果没有提供。根据我的测试,您必须将它添加到index.php中。

现在的代码应该工作良好:)我会很高兴,如果它帮助别人。

@tintinboss和@dJomp的回答把我分类了。然而,我仍然需要从登录用户那里获得信息,这确实花了我很长时间。在这里,我将分享最终版本,它将使你远离这个可怕的循环。

$config = require 'config.php';
require_once( "Hybrid/Auth.php" );
require_once( "Hybrid/Endpoint.php" );
if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done'])) {
    Hybrid_Endpoint::process();
} else {
    try {
        $hybridauth = new Hybrid_Auth( $config );
        $google = $hybridauth->authenticate( "Google");
        $user_profile = $google->getUserProfile();
        echo "Hi there! " . $user_profile->email; 
    } catch( Exception $e ){
        echo "Ooophs, we got an error: " . $e->getMessage();
    }
}

你好,我已经尝试了这个问题的所有解决建议,但都没有解决。我这样解决了这个问题。

" base_url"=>"http://"。$ _SERVER SERVER_NAME"。"inauth/身份验证",

这里的关键点是服务器名称。此外,cookie正在记录您的会话,您不能预览您所做的更改。清除cookies并重试

我们正在使用nginx,我们通过添加来修复它?$args到我们的位置块。如果没有它,请求不会传递hauth_done。

location / {
    try_files $uri $uri/ /index.php?$args;
}