【问题标题】:Can an oauthed cordova app auth a in-app webview?oauthed cordova 应用程序可以对应用内 webview 进行身份验证吗?
【发布时间】:2014-09-15 01:09:37
【问题描述】:

我有一个 Cordova 应用程序,它可以授权进入 Facebook 等外部服务。一旦通过身份验证,在某些情况下,该应用程序将在应用程序内浏览器中打开 facebook.com 以显示帖子或消息。但是当导航到 Facebook.com/post/... 时,用户经常被要求再次登录; webview 没有被授权...

是否有任何方法让获得授权的应用以某种方式(cookie?)将 Facebook 身份验证令牌注入 Web 视图,以避免出现登录屏幕?

谢谢。

【问题讨论】:

    标签: android ios facebook cordova oauth


    【解决方案1】:

    如果您使用 InAppBrowser 插件,您可以从 Facebook 登录中获取网址。 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'});
        }
    }
    

    【讨论】:

    • oauth 过程没有问题。在 oauth 之后,我想在 Facebook 上打开帖子或消息。那时,即使用户登录到我的应用程序 (oauth),我猜应用内浏览器也没有 auth cookie,因此用户会看到另一个登录屏幕。
    猜你喜欢
    • 1970-01-01
    • 2019-09-12
    • 2012-09-26
    • 1970-01-01
    • 2020-11-16
    • 2014-04-05
    • 1970-01-01
    • 2011-06-27
    • 2019-01-30
    相关资源
    最近更新 更多