Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Extension identity: OAuth2 request failed: Service responded with error: 'bad request'

I followed https://developer.chrome.com/extensions/tut_oauth exactly step by step but I am stuck at

https://developer.chrome.com/extensions/tut_oauth#identity_permission

where after I execute my extension, instead of getting the token, I get the error:

Unchecked runtime.lastError while running identity.getAuthToken: 
OAuth2 request failed: Service responded with error: 'bad request'

Please suggest what is the possible cause of this error.

like image 536
Garima Avatar asked Jul 31 '18 17:07

Garima


2 Answers

tl;dr

Update the scopes to the following if its empty,

 "oauth2": {
    "client_id": "yourExtensionOAuthClientIDWillGoHere.apps.googleusercontent.com",
    "scopes":["https://www.googleapis.com/auth/userinfo.email"]
  }

People who were following the tutorial on OAuth2: Authenticate Users with Google

If you've landed into this problem, it is probably because it's 2020 and the documentation isn't updated.

The tutorial asks you to,

Include the "oauth2" field in the extension manifest. Place the generated OAuth client ID under "client_id". Include an empty string in "scopes" for now.

{
  "name": "OAuth Tutorial FriendBlock",
  ...
  "oauth2": {
    "client_id": "yourExtensionOAuthClientIDWillGoHere.apps.googleusercontent.com",
    "scopes":[""]
  },
  ...
}

but never updates it before calling the identity API call to fetch the token.

Updating the scopes, with the following should fix the issue,

"scopes": ["https://www.googleapis.com/auth/userinfo.email"]
like image 58
pratZ Avatar answered Oct 23 '22 08:10

pratZ


I think that's because the scope is empty. I was like you follow the article, but found the problem is from the scope area.

like image 13
Mohammed AlBanna Avatar answered Oct 23 '22 07:10

Mohammed AlBanna