2014-07-23 136 views
0

我有一個cordova應用程序,可以將其作爲Facebook等外部服務。一旦確認,在某些情況下,應用程序將在應用內瀏覽器中打開facebook.com以顯示帖子或消息。但是當瀏覽到Facebook.com/post/ ...時,用戶經常被要求重新登錄; webview是未經授權...是否可以在應用程序中查看應用程序的web應用程序?

是否有任何方式爲應用程序,這是授權,以注入Facebook身份驗證令牌到Web視圖以某種方式(cookie?),以避免該登錄屏幕?

謝謝。

回答

1

如果您使用的是InAppBrowser插件,您可以從Facebook登錄獲取URL。 Facebook身份驗證令牌應該是其中的一部分。

類似於發生在這裏(OpenFB)什麼:

/** 
* Called either by oauthcallback.html (when the app is running the browser) or by the loginWindow loadstart event 
* handler defined in the login() function (when the app is running in the Cordova/PhoneGap container). 
* @param url - The oautchRedictURL called by Facebook with the access_token in the querystring at the ned of the 
* OAuth workflow. 
*/ 
function oauthCallback(url) { 
    // Parse the OAuth data received from Facebook 
    var queryString, 
     obj; 

    loginProcessed = true; 
    if (url.indexOf("access_token=") > 0) { 
     queryString = url.substr(url.indexOf('#') + 1); 
     obj = parseQueryString(queryString); 
     tokenStore['fbtoken'] = obj['access_token']; 
     if (loginCallback) loginCallback({status: 'connected', authResponse: {token: obj['access_token']}}); 
    } else if (url.indexOf("error=") > 0) { 
     queryString = url.substring(url.indexOf('?') + 1, url.indexOf('#')); 
     obj = parseQueryString(queryString); 
     if (loginCallback) loginCallback({status: 'not_authorized', error: obj.error}); 
    } else { 
     if (loginCallback) loginCallback({status: 'not_authorized'}); 
    } 
} 
+0

基於OAuth的認證過程是沒有問題的。在oauth之後,我想在Facebook上打開帖子或消息。在這一點上,即使用戶登錄到我的應用程序(oauth),我猜測,應用程序內瀏覽器沒有auth cookie,因此用戶會看到另一個登錄屏幕。 – nicholas

相關問題