Google social login


#1

I want use Google login integration in electron framework but I have some problem:
I used nodejs module called express to serve an html page on localhost to render the login button because google login not work with origin “file://” but work with “http://locahost”.

This is my code:

<body>
    <span id="signinButton">
      <span
        class="g-signin"
        data-callback="signinCallback"
        data-clientid="MYCLIENTID.apps.googleusercontent.com"
        data-cookiepolicy="none"
        data-requestvisibleactions="http://schemas.google.com/AddActivity"
        data-scope="https://www.googleapis.com/auth/plus.login https://www.google.com/analytics/feeds/ https://mail.google.com/mail/feed/atom/ https://www.google.com/calendar/feeds/"
        data-accesstype="offline" data-approvalprompt="force">
      </span>
    </span>

    <script type="text/javascript">

        // This function will attempt to remove a cookie from all paths.
        var pathBits = location.pathname.split('/');
        var pathCurrent = ' path=';

        // do a simple pathless delete first.
        document.cookie = name + '=; expires=Thu, 01-Jan-1970 00:00:01 GMT;';

        for (var i = 0; i < pathBits.length; i++) {
            pathCurrent += ((pathCurrent.substr(-1) != '/') ? '/' : '') + pathBits[i];
            document.cookie = name + '=; expires=Thu, 01-Jan-1970 00:00:01 GMT;' + pathCurrent + ';';
        }

        (function () {
            var po = document.createElement('script');
            po.type = 'text/javascript';
            po.async = true;
            po.src = 'https://apis.google.com/js/client:plusone.js';
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(po, s);
        })();

        function signinCallback(authResult) { // this is not fired
            console.log(authResult);
        }
    </script>
</body>

signin callback function is not fired.neither add callback in global scope

    (function () {
            var po = document.createElement('script');
            po.type = 'text/javascript';
            po.async = true;
            po.src = 'https://apis.google.com/js/client:plusone.js';
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(po, s);

            var signinCallback = function(authResult) { // this is not fired
                console.log(authResult);
            }
        })();

or force adding it in window object

    (function () {
            var po = document.createElement('script');
            po.type = 'text/javascript';
            po.async = true;
            po.src = 'https://apis.google.com/js/client:plusone.js';
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(po, s);

            window["signinCallback"] = function(authResult) { // this is not fired
                console.log(authResult);
            }
        })();

this code work like a charm in nw.js, so is a scope problem or other?