【问题标题】:Google Adminsdk Directory API accessGoogle Adminsdk 目录 API 访问权限
【发布时间】:2020-07-31 09:26:28
【问题描述】:

我正在尝试获取使用指定客户 ID 注册的 chrome 设备列表。

我已完成以下步骤。

  1. 已启用 Google Admin Directory API
  2. 创建服务帐户并下载 jwt.json 文件 连接性。
  3. 启用域范围的 G-Suite 委派特权。
  4. 将此客户端 ID 注册为通过 Google 授权的 API 客户端 管理员(管理 API 客户端访问)

    客户 ID:我们的客户 ID API 范围:查看和管理您的 Chrome 操作系统设备的元数据https://www.googleapis.com/auth/admin.directory.device.chromeos 查看您的 Chrome 操作系统设备的元数据https://www.googleapis.com/auth/admin.directory.device.chromeos.readonly 接下来我使用我的 Node 模块生成 JWT 访问权限

令牌创建成功。

{"access_token":"ya29.c.KpEB****K*********lufaGlx5k********hvAdADxBhOA****8R3rnTPKKnVb97sdPFG66wHy4FPrnx6KskafKXrBBfEgILdDelP-n5irpKm5h8y8oBWHO*******Xg","token_type":"Bearer","expiry_date":1587150649000,"refresh_token":"jwt-placeholder"}

现在我正在尝试使用此承载令牌来访问以下 API

https://www.googleapis.com/admin/directory/v1/customer/ourcustomerid/devices/chromeos

这总是给出以下错误。

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

    "code": 403,
    "message": "Not Authorized to access this resource/api"
  }
}

不确定是什么问题。

【问题讨论】:

    标签: node.js jwt google-admin-sdk google-chrome-os


    【解决方案1】:

    它在adding Impersonated users email address之后工作......原来是

    const jwtAuth = new google.auth.JWT(
                quickstart.client_email,
                null,
                quickstart.private_key,
                [
                    'https://www.googleapis.com/auth/admin.directory.device.chromeos',
                    'https://www.googleapis.com/auth/admin.directory.device.chromeos.readonly'
                ]
    );
    

    然后我将主题添加为模拟用户电子邮件地址。

    const jwtAuth = new google.auth.JWT(
                quickstart.client_email,
                null,
                quickstart.private_key,
                [
                    'https://www.googleapis.com/auth/admin.directory.device.chromeos',
                    'https://www.googleapis.com/auth/admin.directory.device.chromeos.readonly'
                ],
                'email address of the impersonated user',
    );
    

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 2018-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 2017-01-03
      • 2019-03-03
      • 1970-01-01
      相关资源
      最近更新 更多