user2602584
user2602584

Reputation: 797

OAuth2 User Info in Chrome Identity API

I am working with Google Chrome Identity API, i get successfully the access token and i send it to my backend Server.

To validate the access token i am using this URL :

https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=xxxxxx

I need to get the userId of the authenticated user, how i can do it?

I am using this scopes in the manifest.json file.

https://www.googleapis.com/auth/plus.profile

Upvotes: 2

Views: 1624

Answers (2)

user2602584
user2602584

Reputation: 797

My Solution :

When i ask for an access token in the interactive mode i got the userId (Sub parameter), but if i do it in interactive = false mode the response have no sub parameter.

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

Upvotes: 0

abraham
abraham

Reputation: 47883

The response to https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=xxxxxx includes the userId as the sub value.

{
 "azp": "407408718192.apps.googleusercontent.com",
 "aud": "407408718192.apps.googleusercontent.com",
 "sub": "114233674199568482864",
 "scope": "https://www.googleapis.com/auth/userinfo.profile",
 "exp": "1436369027",
 "expires_in": "3589",
 "access_type": "offline"
}

Alternatively you can make a request to people.get and use the id value.

{
 "kind": "plus#person",
 "etag": "\"RqKWnRU4WW46-6W3rWhLR9iFZQM/gLREuMULAxw3wiBcudkUCAWTcjE\"",
 "objectType": "person",
 "id": "114233674199568482864",
 "displayName": "Abraham Williams",
 ...
}

Upvotes: 4

Related Questions