tin*_*oss 17 php oauth hybridauthprovider hybridauth
我试图在这个简单的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" => ""
);
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?我觉得在搜索互联网很长时间后,它根本不起作用.如果是这样的话,有人可以指出更好的替代开源/免费社交登录图书馆吗?
小智 23
除了tintinboss自己的答案之外,我发现我还需要检查hauth_done(这是测试Facebook的一个例子):
if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done']))
{
Hybrid_Endpoint::process();
}
Run Code Online (Sandbox Code Playgroud)
这终于搞定了 - 感谢tintinboss的有用答案!
tin*_*oss 20
好吧,我自己解决了.
如前所述,文档真的不好.对于希望将来集成此代码的任何人来说,这是一个解决方案
首先,你必须在config.php中创建这样的baseurl
"base_url" => "http://yoursite.com/subdomain/index.php", OR
"base_url" => "http://yoursite.com/index.php",
Run Code Online (Sandbox Code Playgroud)
请注意,我没有使用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();
}
Run Code Online (Sandbox Code Playgroud)
如果未提供,端点进程将使您重定向到空白页.并且你必须将它添加到index.php,就我测试过.
现在代码应该工作正常:)我会很高兴,如果它可以帮助某人.
小智 7
@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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14112 次 |
| 最近记录: |