Chrome身份API中的OAuth2用户信息



我正在使用Google Chrome身份API,我成功获得访问令牌,并将其发送到我的后端服务器。

为了验证访问令牌,我使用以下URL:

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

我需要获得认证用户的userId,我该怎么做?

我在清单中使用这个作用域。json文件。

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

https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=xxxxxx的响应包括userId作为sub值。

{
 "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"
}

或者你可以向别人提出请求。获取并使用id

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

我的解决方案:

当我在interactive mode中请求访问令牌时,我得到了userId (Sub参数),但如果我在interactive = false模式下这样做,则响应没有sub参数。

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

最新更新