Crosswalk webview does not work with accounts-google login

I manually installed crosswalk webview (11) to meteor project.

However after that the login functionality is partially broken. The logged in cookie set by inappbrowser is not available to the crosswalk webview, thus logged in user is not able to access google resources, he/she should be able to access.

Hi, I fixed this issue (whew! finally) by
updating the meteor oauth package to work using redirect (even though the oauth still uses hardcoded loginStyle popup).

Approach

  1. Update the asset end_of_popup_response.html in oauth package to conditionally redirect to http://meteor.local/login?oauthCredentials={secret:,token:}
    (if isCordova)

  2. Update the login.js on rendered function to then call

    Package.oauth.OAuth._handleCredentialSecret
    and
    Accounts.callLoginMethod({
    methodArguments: [{
    oauth: {
    credentialToken: data.oauthCredentials.credentialToken,
    credentialSecret: data.oauthCredentials.credentialSecret
    }
    }],
    userCallback: callback && function (err) {
    callback(convertError(err));
    }
    });

    <html>
<head>
    <script type="text/javascript">
        function storeAndClose() {
            var credentialString= "";
            var config = JSON.parse(document.getElementById("config").innerHTML);
            console.log('store and close');
            if (config.setCredentialToken) {
                console.log('setCredentialToken');
                var credentialToken = config.credentialToken;
                var credentialSecret = config.credentialSecret;
                if (config.isCordova) {
                    console.log('isCordova -stringify');
                    credentialString = JSON.stringify({
                        credentialToken: credentialToken,
                        credentialSecret: credentialSecret
                    });
                    window.location.hash = credentialString;
                }
                if (window.opener && window.opener.Package &&
                        window.opener.Package.oauth) {
                    console.log('all well-cordova in app browser in place');
                    window.opener.Package.oauth.OAuth._handleCredentialSecret(
                            credentialToken, credentialSecret);
                } else {
                    try {
                        console.log('store in sessionsstorage');
                        localStorage[config.storagePrefix + credentialToken] = credentialSecret;
                        console.log(JSON.stringify(config));
                        if (config.isCordova) {
                            console.log('This is cordova... assuming android and redirecting ');
                            window.location.href = "http://meteor.local/login?oauthCredentials="+encodeURIComponent(credentialString);
                            return;
                        }
                    } catch (err) {
                        // We can't do much else, but at least close the popup instead
                        // of having it hang around on a blank page.
                    }
                }
            }
            if (!config.isCordova) {
                document.getElementById("completedText").style.display = "block";
                window.close();
            }
            else {
                console.log('This is cordova... assuming android and redirecting 2');
                window.location.href = 'http://meteor.local/login?oauthCredentials='+encodeURIComponent(credentialString);
                return; 
            }
        }
    </script>
</head>
<body onload="storeAndClose()">
<p id="completedText" style="display:none;">
    Login completed. <a href="#" onclick="window.close()">
    Click here</a> to close this window.
</p>
<div id="config" style="display:none;">##CONFIG##</div>
</body>
</html>
1 Like