0

*如果有兴趣,请参阅 Foursquare 对此问题的回答,作为对这篇文章的评论*

请帮忙,我还在为此奋斗:(

我创建了一个删除所有 Foursquare 相关 cookie 的按钮。使用 Firebug 检查,单击时未设置 cookie。

当用户第一次登录时,同样的程序也会删除插入到数据库中的令牌。在数据库中签入时,该行被删除。

这就是发生的事情:

  1. 在没有 cookie 的全新浏览器中,用户登录。
  2. 设置 Cookie 并在数据库中插入带有令牌和用户 ID 的行。
  3. 用户注销。
  4. 未设置 Cookie 并从数据库中删除行

  5. 现在,另一个用户想要登录。他/她 <a href='".$authorizeUrl."'>Log in</a> 在我的网络应用程序中单击。

  6. Foursquare 登录页面显示,但在他/她可以填写表格之前,该页面使用以前的用户令牌和信息重定向回我的 Web 应用程序!

在不发生第 6 点的情况下,我可以干净启动的唯一方法是手动从浏览器中删除所有 cookie :(

任何想法将不胜感激,我不知道该去哪里。在我正在使用的代码下方,请尝试一下,您会看到第 6 步是如何发生的。

万分感谢

<?php

ob_start();
require_once('includes/EpiCurl.php');
require_once('includes/EpiSequence.php');
require_once('includes/EpiFoursquare.php');


$logout= $_GET['logout']; 
if ($logout == 'true'){ /*I'm deleting all the cookies foursquare related just in case*/
        $pastdate = mktime(0,0,0,1,1,1970);
               setcookie ("XSESSIONID", "", time() - 18600);
           setcookie ("access_token", "", time() - 18600);
           setcookie ("ext_id", "", time() - 18600);
           setcookie ("LOCATION", "", time() - 18600);
           setcookie("access_token", "", $pastdate);
           setcookie("XSESSIONID", "", $pastdate);
           setcookie("ext_id", "", $pastdate);
           setcookie("LOCATION", "", $pastdate);
           setcookie("_chartbeat2", "", $pastdate);
           setcookie("__utmb", "", $pastdate);
           setcookie("__utmc", "", $pastdate);
           setcookie("__utma", "", $pastdate);
           setcookie("__utmz", "", $pastdate);
           $_SESSION['XSESSIONID']=false;
            unset($_SESSION['XSESSIONID']);


 } 

$clientId = "yyyyyyyyy";
$clientSecret = "xxxxx";
$redirectUrl = 'mypage.php';


   $fsObjUnAuth = new EpiFoursquare($clientId, $clientSecret);

      $thecode = $_GET['code'];

 if(!isset($thecode) && !isset($_COOKIE['access_token'])) { //not in yet

     $authorizeUrl = $fsObjUnAuth->getAuthorizeUrl($redirectUrl); 


    echo"<a href='".$authorizeUrl."'>Let's log in</a>";

 }else{  /*we're in*/



    if(!isset($_COOKIE['access_token'])) {  


         $token = $fsObjUnAuth->getAccessToken($thecode, $redirectUrl);
          setcookie('access_token', $token->access_token);
          $_COOKIE['access_token'] = $token->access_token;     

   }  
        $fsObjUnAuth->setAccessToken($_COOKIE['access_token']);


      echo "we're in";

     echo"<br><a href='mypage.php?logout=true'>Logout</a>";   

 }             

?>
4

2 回答 2

1

您是否尝试在取消设置之前更改 cookie 的到期日期的值?似乎未设置不会破坏cookie。

于 2011-03-28T16:14:18.553 回答
1

您本身不能真正“注销”。根据 Foursquare 文档,令牌永远不会过期。你做的一切都是正确的。你需要打https://foursquare.com/oauth2/authorize而不是https://foursquare.com/oauth2/authenticate。点击/authorize将强制用户重新验证他们的身份,(重新登录),并重新授权您的应用程序,为您提供一个新的访问令牌以在本地存储您的应用程序。

于 2011-12-10T03:46:42.843 回答