HybridAuth/PHP Facebook SDK身份验证失败(getUser返回0) [英] HybridAuth / PHP Facebook SDK authentication failed (getUser returns 0)

查看:162
本文介绍了HybridAuth/PHP Facebook SDK身份验证失败(getUser返回0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置HybridAuth,我还处于早期阶段.现在,我要做的就是连接并确保HA将重定向到facebook并提示安装应用程序,然后在用户返回时对用户进行身份验证.

I'm trying to configure HybridAuth and I'm in the very early stages. Right now all I want to do is connect and make sure HA will redirect to facebook and prompt for app installation, then authenticate the user when they get back.

我正在通过以下方式手动致电: http://mydomain.com/auth.php?provider=Facebook

I'm manually calling the following from: http://mydomain.com/auth.php?provider=Facebook

auth.php看起来像这样:

auth.php looks like this:

session_start();
require_once($_SERVER['DOCUMENT_ROOT'] . "/func/db_connect.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/api/auth/Hybrid/Auth.php");      // HybridAuth Module 

$hybridauth_config = include($_SERVER['DOCUMENT_ROOT'] . '/api/auth/config.php');

if ($_GET['provider'] == '' || !in_array($_GET['provider'], array_keys($hybridauth_config['providers']))) {
    echo 'Invalid Provider';
} else {
    try { 
        $hybridauth = new Hybrid_Auth($hybridauth_config);

        // try to authenticate with this provider
        $adapter = $hybridauth->authenticate($_GET['provider']);

        // grab user profile
        if ($hybridauth->isConnectedWith($f_provider)) {
            // yep, we're connected.  Add this provider's info to the user_auth table
            echo 'connection successful';
        }

    } catch (Exception $e) {
        echo $e->getMessage();
    }
}

它的工作方式是转发到Facebook,并提示您使用适当的权限安装正确的应用程序.这告诉我我的HA配置工作正常.我成功安装了该应用程序,然后将其重定向回页面,并在其中收到消息:

It works in that it forwards to Facebook and prompts to install the correct app with the appropriate permissions. That tells me my HA config is working fine. I install the app successfully and it then redirects back to the page, where I get the message:

Authentification failed! Facebook returned an invalide user id.

有什么作用?我的应用程序在FB控制面板中也显示0个添加和0个API调用(尽管此数据看起来可能会延迟几天).我是否在等待FB以某种方式启用该应用程序?我在做错什么吗?

What gives? My App shows 0 adds and 0 API calls in the FB control panel too (although this data looks like it might be delayed a few days). Am I waiting for FB to enable the app in some way? Am I doing something wrong?

更新

HybridAuth使用Facebook SDK,因此我试图从整个等式中消除HA.运行以下基本示例:

HybridAuth uses the Facebook SDK so I tried to just eliminate HA from the whole equation. Running the following basic example:

session_start();

require($_SERVER['DOCUMENT_ROOT'] . "/path/to/fbsdk/facebook.php");
$facebook = new Facebook(array(
  'appId'  => 'myappid',
  'secret' => 'myappsecret',
  'fileUpload' => true
));

$user = $facebook->getUser();
var_dump($user);

我已登录Facebook,并添加了应用程序,但是无论我做什么,用户ID都会返回0.我也尝试过使用测试用户-无济于事.我在这里可能会缺少一些服务器配置问题吗?

I'm logged in to facebook and I have the application added, but no matter what I do the user ID returns 0. I've tried using the test users as well - to no avail. Is there some server configuration issue I might be missing here?

推荐答案

我将代码移至其他应用程序/服务器,然后又移至其他服务器上的同一应用程序,一切正常.因此,我开始将其作为服务器配置问题进行研究.事实证明,Facebook不喜欢我的开发服务器上的自签名证书.

I moved my code to a different app/server and then to the same app on a different server and everything worked fine. So I started looking into it as a server configuration issue. Turns out Facebook didn't like the self-signed certificate on my development server.

我能够通过更改PHP SDK中的base_facebook.php类并添加curlopt来忽略SSL验证步骤来解决此问题.见下文:

I was able to solve this problem by altering the base_facebook.php class in the PHP SDK and adding the curlopt to ignore the SSL verification step. See below:

  public static $CURL_OPTS = array(
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 60,
    CURLOPT_USERAGENT      => 'facebook-php-3.1',
    CURLOPT_SSL_VERIFYPEER => false
  );

这篇关于HybridAuth/PHP Facebook SDK身份验证失败(getUser返回0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆