6

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 : console log 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>
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Waldo Jeffers
  • 2,289
  • 1
  • 15
  • 19
  • Can you elaborate on the last point, which sounds like it is a little different than the remainder of your post. You're getting the logged_out state immediately after getting the token on Firefox? – Prisoner Jun 05 '14 at 10:04
  • I would like to provide screenshots of console logs, but unfortunately, the 'extra' bug in Firebox happens completely randomly. So far, I have not been able to identify what really triggers my Firefox's "freaked out mode". Most of the time, it behaves like Google Chrome (ie the signInCallback is called twice, but the user is still able to re-log in). – Waldo Jeffers Jun 05 '14 at 10:22
  • But in the "freaked out mode", I'm initially logged out (`error=user_signed_out`), then I click on my Sign In button, then the authentification pop up appears, then instantly disappears because I'm still logged in on my Google Account and have not revoked my access, then the `signInCallback` receives a valid `code` and `access_token`, but then the `signInCallback` is *immediately* called again twice with a `user_signed_out` error. – Waldo Jeffers Jun 05 '14 at 10:23
  • Can you also post the accept block that is used to initialise the g+ button? – MrPotes Jun 06 '14 at 06:13
  • I am not sure I understand what you mean. I edited my post and added the call to the Google API JavaScript. Is that what you meant ? Thanks – Waldo Jeffers Jun 06 '14 at 07:54
  • Hi Have you solved this problem after all ? if yes, would you please share your solution. Thank you. – Ray C Lin Jul 07 '14 at 18:30
  • Hi Ray. No I could not find a way to solve this problem. I think nothing can be done until Google tackles the issue, which apparently they are not willing to do. Check [my post on Google+ Dev Community](https://plus.google.com/105677613146028971470/posts/JhU1rtSMnKQ) – Waldo Jeffers Jul 08 '14 at 09:07
  • This behaviour is closely related to this question http://stackoverflow.com/q/23020733/203371. The answer in there should help you. – Ben Smith Oct 01 '14 at 10:55
  • Thanks for the tip @BenSmith, but as you can see in the screenshots I posted, both callbacks are called with `method` parameter set to `null`, so I believe these are different issues. – Waldo Jeffers Oct 01 '14 at 12:24

1 Answers1

0

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.

Jay
  • 998
  • 1
  • 10
  • 22