[英]PHP HybridAuth social signin not working at all. Redirecting to ?hauth.start=Facebook&hauth.time
I was trying to make HybridAuth Social Login work on this simple php site. 我试图在这个简单的php网站上进行HybridAuth社交登录。 Downloaded HybridAuth and installed it. 下载HybridAuth并安装它。 Then found that even the examples does not work for social login (tried on remote server too. 然后发现即使这些示例也不适用于社交登录(在远程服务器上也尝试过)。
The normal signin_signup example works fine. 正常的signin_signup示例工作正常。 But whenever I click the link to login to a social network (ie, facebook,twitter) it redirects me to (MY_BASE_URL/index.php?hauth.start=Facebook&hauth.time) without showing any login window/error messages at all. 但每当我点击链接登录社交网络(即facebook,twitter)时,它会将我重定向到(MY_BASE_URL / index.php?hauth.start = Facebook&hauth.time),而根本不显示任何登录窗口/错误消息。
I've carefully read the documentations and other solutions posted here. 我仔细阅读了此处发布的文档和其他解决方案。 Adjusted my config.php to have a base url like http://example.com/index.php . 调整我的config.php以获得一个基本网址,如http://example.com/index.php 。 But it just does not respond. 但它只是没有回应。 Is there something I'm missing? 有什么我想念的吗? I've spent 2 days already on it. 我已经花了两天时间。
here is my config.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" => ""
);
Can someone please help me? 有人可以帮帮我吗? I got a feeling that it does not work very good at all after searching the internet for quite a long. 我觉得在搜索互联网很长时间后,它根本不起作用。 If that's the case, can someone point to a better alternative opensource/free social signin library? 如果是这样的话,有人可以指出更好的替代开源/免费社交登录库吗?
Further to tintinboss's own answer, I found I needed to check for hauth_done
as well (this was for an example testing Facebook): 除了tintinboss自己的答案之外,我发现我还需要检查hauth_done
(这是测试Facebook的一个例子):
if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done']))
{
Hybrid_Endpoint::process();
}
This finally got it working - thank you tintinboss for the useful answer! 这终于搞定了 - 感谢tintinboss的有用答案!
Alright, I've solved it myself. 好吧,我自己解决了。
As stated before, the documentation was really not good. 如前所述,文档真的不好。 Here's the solution for anyone who wants to integrate this code in future 以下是希望在将来集成此代码的任何人的解决方案
Firstly, you have to make your baseurl like this in config.php 首先,你必须在config.php中创建这样的baseurl
"base_url" => "http://yoursite.com/subdomain/index.php", OR
"base_url" => "http://yoursite.com/index.php",
Note that I'm not using www. 请注意,我没有使用www。 Don't know why, but it does not work with www. 不知道为什么,但它不适用于www。
Now the tricky part, you have to include this in your index.php file 现在是棘手的部分,你必须在index.php文件中包含它
require_once( "PATH_TO_HYBRID/Auth.php" );
require_once( "PATH_TO_HYBRID/Endpoint.php" );
if (isset($_REQUEST['hauth_start']))
{
Hybrid_Endpoint::process();
}
The Endpoint Process is what makes you redirect to a blank page if not provided. 如果未提供,端点进程将使您重定向到空白页。 And you must add it to the index.php as far as I've tested. 并且你必须将它添加到index.php,就我测试过。
Now the code should work fine :) I'll be happy if it helps someone. 现在代码应该工作正常:)我会很高兴,如果它可以帮助某人。
@tintinboss and @dJomp answers sorted me out. @tintinboss和@dJomp答案把我排除在外。 however I still needed to get info out of the logged in user, which took me long indeed. 但是我仍然需要从登录用户那里获取信息,这确实让我感觉很长。 Here I share the final version that will get you far away from this awful loop. 在这里,我分享最终版本,让你远离这个可怕的循环。
$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();
}
}
Hi I have tried all the solution suggestions of this problem but none have reached the solution. 嗨,我已经尝试了这个问题的所有解决方案建议,但没有达到解决方案。 I solved the problem like this. 我解决了这个问题。
"base_url" => 'http://'.$_SERVER['SERVER_NAME'].'inauth/auth', “base_url”=>'http://'。$_SERVER ['SERVER_NAME']。'usuth / auth',
The key point here is the server name.In addition, cookies are recording your sessions and you can not preview changes you've made. 这里的关键点是服务器名称。此外,cookie正在记录您的会话,您无法预览您所做的更改。 Clear cookies and try again. 清除Cookie并重试。
We are using nginx and we fixed it by adding ?$args to our location block. 我们正在使用nginx,我们通过向我们的位置块添加?$ args来修复它。 Without it, the request does not pass hauth_done. 没有它,请求不会通过hauth_done。
location / {
try_files $uri $uri/ /index.php?$args;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.