繁体   English   中英

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

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

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

正常的signin_signup示例工作正常。 但每当我点击链接登录社交网络(即facebook,twitter)时,它会将我重定向到(MY_BASE_URL / index.php?hauth.start = Facebook&hauth.time),而根本不显示任何登录窗口/错误消息。

我仔细阅读了此处发布的文档和其他解决方案。 调整我的config.php以获得一个基本网址,如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']。'usuth / auth',

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM