Access error when using gapi.auth.authorize

I am trying to access a third party API that uses the Google API, but for that I need to use gapi.auth.authorize to get google information to navigate to their API. I am using the new email scope after figuring out that userinfo / email is out of date, but I am still getting the access_denied error.

Here is my version that I'm having problems with ...

index.html

<!doctype html>
<html>
<head>
</head>
<body>
   <p>Tripping all day...</p>
   <p id="output"></p>
   <script src="auth.js"></script>

   <script type="text/javascript">
       function init() {
       console.log('init');
       checkAuth();
       }
   </script>
   <script src="https://apis.google.com/js/client.js?onload=init">    </script>
   <script>
      document.getElementById("output").innerHTML = "Coooooorrrrrraaaaalll";
   </script>
`enter code here`</body>
</html>

      

auth.js

CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com';

var SCOPES = 'email';

function handleAuth(authResult) {
    console.log('handle auth');
    console.log(authResult);
}

function checkAuth() {
    console.log('check auth');
    gapi.auth.authorize({client_id: CLIENT_ID, scope: SCOPES, immediate: true, cookie_policy: 'single_host_origin'}, handleAuth);
}

      

The console log spits out this error object when it fails ...

client_id: "xxxxxxxxxxxxx.apps.googleusercontent.com"
cookie_policy: "single_host_origin"
error: "immediate_failed"
error_subtype: "access_denied"
expires_at: "1438103114"
expires_in: "86400"
g_user_cookie_policy: "single_host_origin"
issued_at: "1438016714"
response_type: "token"
scope: "email"
state: ""

      

Any insight into what I am doing wrong or where to look next is appreciated. Thank!

+3


source to share


1 answer


For anyone else having similar issues, I found that if I change the "immediate" parameter in the gap.auth.authorize request to false, a popup appears that allows me to select the Google account to use. From there everything works successfully.



I'm still not 100% on what's going on behind the scenes, but now it works. Eventually, I would like to get immediate authentication without making a popup, but that would probably be a different question.

+3


source







All Articles