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>