【问题标题】:OAuth2 User Info in Chrome Identity APIChrome 身份 API 中的 OAuth2 用户信息
【发布时间】:2015-07-09 15:26:52
【问题描述】:

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

要验证我使用此 URL 的访问令牌:

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

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

我在 manifest.json 文件中使用这个范围。

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

【问题讨论】:

    标签: google-chrome-extension google-chrome-app google-oauth


    【解决方案1】:

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

    或者,您可以向people.get 发出请求并使用id 值。

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

    【讨论】:

    • 是的,当我请求 userInfo 端点 = https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=xxxxxx,响应不包含 userId 但是当我在 交互模式 中询问访问令牌时,我明白了!,谢谢@abraham
    【解决方案2】:

    我的解决方案:

    当我在interactive mode 中请求访问令牌时,我得到了userIdSub 参数),但如果我在interactive = false 模式下执行此操作,则响应没有sub 参数。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-21
      • 2018-02-28
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      相关资源
      最近更新 更多