Google signInCallback called twice when user is signed_out

时光毁灭记忆、已成空白 提交于 2019-12-04 12:14:06

问题


I am using Google Login hybrid flow to authenticate users but I have a strange bug : when users are signed out (authResult['error'] == 'user_signed_out'), the signInCallback is called twice ! It does not happen when the user signs in, so I don't think it is linked to the (rather annoying) 'Welcome Back [user]' prompt.

My code looks like this :

function signInCallback(authResult) {
    console.log("signIn callback called, using " + authResult['status']['method'] + " method");
    console.log("authResult = ");
    console.dir(authResult);

    if (authResult['code']) {
        // do things....
    }else if(authResult.error == "user_signed_out"){
        // do other things...
    }
}

This is what I get on the console : See a larger version

The HTML code I am using :

<div id="signinButton" style="display:<?=(isset($_SESSION['userinfo'])) ? 'none' : 'inline-block'?>">
        <span class="g-signin"
            data-scope="<?=join(' ',$scopes)?>"
            data-clientid="<?=$client_id?>"
            data-redirecturi="<?=$redirect_uri?>"
            data-accesstype="<?=$access_type?>"
            data-cookiepolicy="<?=$cookie_policy?>"
            data-callback="signInCallback"
            data-approvalprompt="<?=$approval_prompt?>"
            data-state="<?=$_SESSION['state']?>"
        ></span>
    </div>

I am using two different Google Accounts on two different browsers. I initially thought it was due to that (Google stores in a cookie the google_account_id and the user state, like G_USERSTATE_H3 : 'google_account_id#1=0&google_account_id#2=1'). But I cleared all my cookies on both browsers, and ran my tests with only one browser open, and one google account. I still get this bug.

This is a very annoying bug. Plus, Google Chrome handles it pretty well, but Firefox is completely freaked out and executes the callback three times, and then, the user is unable to log in (he's logged in for 1s, and is instantly re-signed out).

Could anybody please help me ?

UPDATE : This is how Google JS Api is included :

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

回答1:


This isn't exactly an answer, but whenever I use Chrome this error occurs, but as soon as I switched to Safari it went away. I realize this may not help the OP, but just in case anyone else happens to stumble across this thread, try using a different browser. It worked for me.



来源:https://stackoverflow.com/questions/24056169/google-signincallback-called-twice-when-user-is-signed-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!