2012-02-24 39 views
0

我目前正在开发一个使用官方android FB sdk的android应用程序:所以从认证/授权(SSO)到API调用的所有内容都是通过android FB sdk完成的。Android Facebook应用程序:FB webview(Login webview)cookie有效多久?

但出于安全原因,我不想在手机上存储我的access_token。现在我有一个关于cookie存储的Facebook webview(当您第一次登录时)有点问题。在退出Android应用程序或者终止进程后,似乎即使我没有在设备上存储access_token,我仍然可以访问android应用程序而不提供凭据,因此可能是cookie。

你guyz知道多久了facebook的cookie是有效的

感谢...

回答

0

这里是被Facebook本身的清除Cookies的实施。

public static void clearFacebookCookies(Context context) { 
     // setCookie acts differently when trying to expire cookies between builds of Android that are using 
     // Chromium HTTP stack and those that are not. Using both of these domains to ensure it works on both. 
     clearCookiesForDomain(context, "facebook.com"); 
     clearCookiesForDomain(context, ".facebook.com"); 
     clearCookiesForDomain(context, "https://facebook.com"); 
     clearCookiesForDomain(context, "https://.facebook.com"); 
    } 



private static void clearCookiesForDomain(Context context, String domain) { 
     // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager 
     // has never been created. 
     CookieSyncManager syncManager = CookieSyncManager.createInstance(context); 
     syncManager.sync(); 

     CookieManager cookieManager = CookieManager.getInstance(); 

     String cookies = cookieManager.getCookie(domain); 
     if (cookies == null) { 
      return; 
     } 

     String[] splitCookies = cookies.split(";"); 
     for (String cookie : splitCookies) { 
      String[] cookieParts = cookie.split("="); 
      if (cookieParts.length > 0) { 
       String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;"; 
       cookieManager.setCookie(domain, newCookie); 
      } 
     } 
     cookieManager.removeExpiredCookie(); 
    } 

如果你有Facebook SDK连接到你的项目为lib。只需调用Session.getActiveSession()。clearFacebookCookies(getApplicationContext());