Acquire permissions to retrieve user profile info

348 views Asked by At

I have this call (I removed error-handling for brevity's sake):

chrome.identity.getAuthToken({interactive: true}, function (token) {

 let req = new XMLHttpRequest();
    req.open('GET', 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + token);
    req.onload = function() {
      console.log('this userinfo => ', req.response);
    };
    req.send();  

});

I get this logged:

this userinfo =>  {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "insufficientPermissions",
    "message": "Insufficient Permission"
   }
  ],
  "code": 403,
  "message": "Insufficient Permission"
 }
}

I believe that I need to add the following to my manifest.json file...

before I have this:

  "oauth2": {
    "client_id": "5461307462-7gebv03xxx9csfidfg5f6ggxxxrju9374.apps.googleusercontent.com",
    "scopes": [
      "https://www.googleapis.com/auth/chromewebstore.readonly"
    ]
  },

then I add this:

  "oauth2": {
    "client_id": "5461307462-7gebv03xxx9csfidfg5f6ggxxxrju9374.apps.googleusercontent.com",
    "scopes": [
      "https://www.googleapis.com/oauth2/v1/userinfo",
      "https://www.googleapis.com/oauth2/v1/userinfo.picture",
      "https://www.googleapis.com/auth/chromewebstore.readonly"
    ]
  },

the problem though, is that the authentication method then changes. I no longer get this view:

enter image description here

instead I get a new Chrome tab that looks like this:

enter image description here

the problem is, no matter how many times I login, it always bounces back to the same login tab. Furthermore, I cannot access any other Chrome tab, it keeps bouncing me back to the same Chrome auth tab. It's so weird and such an awful experience.

Does anyone know what might be going on?

1

There are 1 answers

5
Iván Nokonoko On

Most likely, the problem is that the scopes you request have invalid addresses (where did you get them from?)

Try changing: https://www.googleapis.com/oauth2/v1/userinfo

by: https://www.googleapis.com/auth/userinfo.email and/or https://www.googleapis.com/auth/userinfo.profile

Maybe the scope https://www.googleapis.com/auth/userinfo works as well.

You can also check the useful Google APIs Explorer.