title: Why is Google login returning “immediate_failed” even when user logged somewhere else?
body: <p>I am aware of similar questions but still have the problem:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/15863349/immediate-failed-could-not-automatially-log-in-the-user">&quot;immediate_failed&quot; - Could not automatially log in the user</a></li>
  <li><a href="https://stackoverflow.com/questions/23082672/google-login-callback-always-shows-immediate-failed">Google login callback always shows &quot;immediate_failed&quot;</a></li>
  <li><a href="https://stackoverflow.com/questions/17894861/google-plus-signin-immediate-failed-error">Google plus signin &quot;immediate_failed&quot; error</a></li>
  </ul>
  
  <p>I also understand that the sign in callback is called initially even without request to check if the user is logged somewhere else. The “immediate_failed” is also returned correctly when the user is logged out within the browser from other Google services. However, when the user is in fact logged in Gmail in another Tab, I still receive the same failure in javascript. </p>
  
  <p>This is the plain Google login code example. What could be wrong?. Some information:</p>
  
  <p>Credentials:</p>
  
  <pre><code>Redirect URIs http://localhost:8000/beta/oauth2callback
  Javascript Origins http://localhost:8000
  </code></pre>
  
  <p>Relevant Code (Javascript only sign in, copied and only slightly modified from: <a href="https://developers.google.com/+/web/signin/add-button" rel="nofollow noreferrer">https://developers.google.com/+/web/signin/add-button</a>)</p>
  
  <p>Button declaration:</p>
  
  <pre><code>   &lt;div class="g-signin" data-callback="loginFinished"
      data-clientid="268583......"
      data-scope="profile email"
      data-cookiepolicy="single_host_origin"
      &gt;
  </code></pre>
  
  <p>Callback:</p>
  
  <pre><code>var loginFinished = function(authResult) {
  
      console.log(authResult)
  
      if (authResult['code']) {
        var el = document.getElementById('oauth2-results');
        var label = '';
        toggleDiv('oauth2-results');
        if (authResult['status']['signed_in']) {
          label = 'User granted access:';
          gapi.auth.setToken(authResult);
        } else {
          label = 'Access denied: ' + authResult['error'];
        }
        el.innerHTML =
            label + '&lt;pre class="prettyprint"&gt;&lt;code&gt;' +
            // ..
            '}&lt;/code&gt;&lt;/pre&gt;';
        toggleDiv('signin-button');
      } else {
        document.getElementById('oauth2-results').innerHTML =
            'Error';
      }
    };
  </code></pre>
  
  <p>Full code (served locally by Apache on :8000/test0/signin_demo_basic.htm)</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Google+ Sign-in button demo&lt;/title&gt;
    &lt;style type="text/css"&gt;
    html, body { margin: 0; padding:0;}
    #signin-button {
     padding: 5px;
    }
  
    #oauth2-results pre { margin: 0; padding:0;}
    .hide { display: none;}
    .show { display: block;}
    &lt;/style&gt;
    &lt;script type="text/javascript"&gt;
  
    var loginFinished = function(authResult) {
  
      console.log(authResult)
  
      if (authResult['code']) {
        var el = document.getElementById('oauth2-results');
        var label = '';
        toggleDiv('oauth2-results');
        if (authResult['status']['signed_in']) {
          label = 'User granted access:';
          gapi.auth.setToken(authResult);
        } else {
          label = 'Access denied: ' + authResult['error'];
        }
        el.innerHTML =
            label + '&lt;pre class="prettyprint"&gt;&lt;code&gt;' +
            // JSON.stringify doesn't work in IE8.
            '{&lt;br /&gt;' +
            '  "id_token" : "' + authResult['id_token'] +'",&lt;br /&gt;' +
            '  "access_token" : "' + authResult['access_token'] + '",&lt;br /&gt;' +
            '  "state" : "' + authResult['state'] + '",&lt;br /&gt;' +
            '  "expires_in" : "' + authResult['expires_in'] + '",&lt;br /&gt;' +
            '  "error" : "' + authResult['error'] + '",&lt;br /&gt;' +
            '  "error_description" : "' + authResult['error_description'] + '",&lt;br /&gt;' +
            '  "authUser" : "' + authResult['authuser'] + '",&lt;br /&gt;' +
            '  "status" : {"' + '&lt;br /&gt;' +
            '    "google_logged_in" : "' + authResult['status']['google_logged_in'] + '",&lt;br /&gt;' +
            '    "method" : "' + authResult['status']['method'] + '",&lt;br /&gt;' +
            '    "signed_in" : "' + authResult['status']['signed_in'] + '"&lt;br /&gt;' +
            '  }&lt;br /&gt;' +
            '}&lt;/code&gt;&lt;/pre&gt;';
        toggleDiv('signin-button');
      } else {
        document.getElementById('oauth2-results').innerHTML =
            'Error';
      }
    };
  
    function toggleDiv(id) {
      var div = document.getElementById(id);
      if (div.getAttribute('class') == 'hide') {
        div.setAttribute('class', 'show');
      } else {
        div.setAttribute('class', 'hide');
      }
    }
    &lt;/script&gt;
    &lt;script src="https://plus.google.com/js/client:platform.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id="signin-button" class="show"&gt;
     &lt;div class="g-signin" data-callback="loginFinished"
      data-clientid="268583......"
      data-scope="profile email"
      data-cookiepolicy="single_host_origin"
      &gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;div id="oauth2-results" class="hide"&gt;&lt;/div&gt;
    &lt;div&gt;&lt;a href="javascript:document.location.reload();"&gt;Reload the example&lt;/a&gt; or &lt;a
      href="/+/demos/signin_demo_basic" target="_blank"&gt;open in a new window&lt;/a&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>