无法在 IE 中进行身份验证

发布于 2024-12-10 20:40:06 字数 1985 浏览 0 评论 0原文

我成为 Facebook 开发人员已经有一段时间了,但我刚刚开始使用新的 Facebook 应用程序布局,并停留在第一步中。所以显然我旧的身份验证方法不再起作用了。

为了解决这个问题,我尝试了 http://developers.facebook.com/docs 中给出的示例/身份验证/。但是,它似乎在 Internet Explorer 上根本不起作用。

下面是我的代码:

<?php 
$app_id = "-----";
$app_secret = "------";
$my_url = "http://apps.facebook.com/myapp/";
require('facebook-php-sdk-2343fca/src/facebook.php');
$facebook = new Facebook(array(
                           'appId'  => $app_id,
                           'secret' => $app_secret,
                           'cookie' => true,));
$session = $facebook->getSession();
session_start();
$code = $_REQUEST["code"];
echo $_REQUEST['state']." == ".$_SESSION['state'];

if(empty($code)) {
    $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
       . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="    
       . $_SESSION['state']  . '&scope=publish_stream,read_stream,user_photos,friends_photos,user_events,friends_events';
    echo("<script> top.location.href='" . $dialog_url . "'</script>");
}

if($_REQUEST['state'] == $_SESSION['state']) {
    $token_url = "https://graph.facebook.com/oauth/access_token?"
    . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
    . "&client_secret=" . $app_secret . "&code=" . $code;

    $response = file_get_contents($token_url);
    $params = null;
    parse_str($response, $params);

    $graph_url = "https://graph.facebook.com/me?access_token=" 
       . $params['access_token'];

    $user = json_decode(file_get_contents($graph_url));
    //echo("Hello " . $user->name);

//My app goes here!
   } else {
    echo("The state does not match. You may be a victim of CSRF.");
}
?>

到目前为止,我所知道的是问题与 $_SESSION['state']; 有关。

任何帮助将非常感激!

I've been a Facebook developer for a while now, but I'm starting fresh with the new Facebook App layout and stuck one of the first steps. So apparently my old method of authentication doesn't work anymore.

To solve this, I tried the one given as an example at http://developers.facebook.com/docs/authentication/ . However, it doesn't seem to work at all on internet explorer.

Here's my code right below:

<?php 
$app_id = "-----";
$app_secret = "------";
$my_url = "http://apps.facebook.com/myapp/";
require('facebook-php-sdk-2343fca/src/facebook.php');
$facebook = new Facebook(array(
                           'appId'  => $app_id,
                           'secret' => $app_secret,
                           'cookie' => true,));
$session = $facebook->getSession();
session_start();
$code = $_REQUEST["code"];
echo $_REQUEST['state']." == ".$_SESSION['state'];

if(empty($code)) {
    $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
       . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="    
       . $_SESSION['state']  . '&scope=publish_stream,read_stream,user_photos,friends_photos,user_events,friends_events';
    echo("<script> top.location.href='" . $dialog_url . "'</script>");
}

if($_REQUEST['state'] == $_SESSION['state']) {
    $token_url = "https://graph.facebook.com/oauth/access_token?"
    . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
    . "&client_secret=" . $app_secret . "&code=" . $code;

    $response = file_get_contents($token_url);
    $params = null;
    parse_str($response, $params);

    $graph_url = "https://graph.facebook.com/me?access_token=" 
       . $params['access_token'];

    $user = json_decode(file_get_contents($graph_url));
    //echo("Hello " . $user->name);

//My app goes here!
   } else {
    echo("The state does not match. You may be a victim of CSRF.");
}
?>

So far, all I know is the problem has to do with $_SESSION['state'];

Any help would be much obliged!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过气美图社 2024-12-17 20:40:06

嗯,我成功了。对于 Internet Explorer 使用 iframe 处理 P3P cookie 来说,这是一个相当模糊的问题。简而言之,只需将其放在代码开头的某个位置即可:

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

您可以在此处阅读更多信息: 如何使用 Facebook PHP SDK 3.0 正确处理会话和访问令牌?

Hmm, I got it working. It's a quite obscure issue with P3P cookies handling by Internet Explorer with iframes. In short, just put this somewhere in the beginning of your code:

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

You can read more here: How to properly handle session and access token with Facebook PHP SDK 3.0?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文