我有一个 cordova 应用程序,可以对 Facebook 等外部服务进行 oauth。一旦授权,在某些情况下,应用程序将在应用程序内浏览器中打开 facebook.com 以显示帖子或消息。但是当导航到 Facebook.com/post/... 时,用户经常被要求重新登录; WebView 未被授权...
有没有什么方法可以让获得授权的应用程序以某种方式(cookie?)将 Facebook 身份验证 token 注入(inject) WebView 以避免登录屏幕?
谢谢。
最佳答案
如果您使用的是 InAppBrowser 插件,您可以从 Facebook 登录中取回 url。 Facebook 授权 token 应该是其中的一部分。
类似于这里发生的事情 ( 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'});
}
}
关于android - 经过验证的 cordova 应用程序可以验证应用程序内的 Web View 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24917445/