【问题标题】:Google Admin SDK - Service account can't access resourceGoogle Admin SDK - 服务帐户无法访问资源
【发布时间】:2017-07-01 10:18:43
【问题描述】:

我通过 console.developers.google.com 创建了服务帐户客户端。生成的密钥、.p12 证书、启用 DwD 等等...... 然后我继续在 Admin API references 中担任描述者。 (HTTP/REST 版本)。这包括在 Google Admin -> Security -> Advancet Settings 中为这些客户端 ID 分配范围。 Current admin security config state 在我成功交换访问令牌的代码并请求我的域下的用户列表后,我得到了这个响应。

{   
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "forbidden",
        "message": "Not Authorized to access this resource/api"
      }
    ],
    "code": 403,
    "message": "Not Authorized to access this resource/api" 
  } 
}

请求是 GET,授权承载 ya29.ElrxA8F[其余的 acctoken] 并且 google 开发控制台仪表板在 Admin SDK 中显示带有错误请求的图表

【问题讨论】:

    标签: rest google-admin-sdk google-oauth service-accounts


    【解决方案1】:

    您必须将您的客户冒充为指定用户

    所以我错过了:json auth payload 中的“sub”参数: 这是正确的 json 对象(当然带有您的 id 等),您需要使用它来从服务帐户访问您的 Admin SDK:

    {
    "iss":"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com", "sub":"some.user@example.com",
    “范围”:“googleapis.com/auth/prediction”,
    "aud":"googleapis.com/oauth2/v4/token",
    “exp”:1328554385,“iat”:1328550785 }

    查看google admin sdk reference 了解更多详情。 (带有“sub”参数的部分)

    【讨论】:

      【解决方案2】:

      您可以参考这个answer,它指出只有super admins, delegated admins and resellers 可以访问Admin SDK Directory API。尝试委派一个只能通过 API 访问更新用户的管理员,然后让您的 Web 应用程序使用为该委派管理员创建的 OAuth 令牌。这也可能是因为 Google App 上的配置错误“在 Google Apps 控制台上添加具有范围的客户端 ID。”。您可以查看this

      【讨论】:

        【解决方案3】:

        对于未来也有这个问题的人。请也重置您的令牌...我花了一天时间不明白为什么我的服务帐户在我的 Google 脚本中出现此错误,即使我已经验证了所有权限。最后,原因是脚本的缓存使用了一个旧令牌,该令牌是在缺少权限的情况下生成的。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-09-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-01-06
          • 2018-05-16
          • 2016-12-24
          • 2018-10-20
          相关资源
          最近更新 更多