【问题标题】:How can I get assigned custom roles of a G Suite user from Google API?如何从 Google API 获取分配给 G Suite 用户的自定义角色?
【发布时间】:2020-01-15 18:15:54
【问题描述】:

我有一个内部应用程序,用户应该能够使用我们公司的 G Suite 凭据登录。我在 G Suite 中创建了几个自定义角色,我计划在应用中使用它们来确定他们可以在那里做什么。

我正在使用 Passport 进行 OAuth2 调用,我使用的范围如下:

scope: [
  'email',
  'https://www.googleapis.com/auth/userinfo.profile',
  'https://www.googleapis.com/auth/admin.directory.rolemanagement.readonly'
]

列表中的最后一个授予我列出在我的应用中登录用户的所有角色的权限。

然后我调用https://www.googleapis.com/admin/directory/v1/customer/<MY_CUSTOMER_ID>/roleassignments?userKey=<MY_USER_ID> 并获取用户分配给他们的角色列表。

问题是,如果我使用我的超级管理员用户,一切都会很好,但是当使用没有超级管理员权限的测试用户时,我会从 Google API 获得以下信息:

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

我很确定我需要授予对 G Suite 中创建的自定义角色的一些访问权限,但我不知道该怎么做。我尝试在角色管理员权限视图中勾选所有内容,但没有任何效果。只有当我授予我的测试帐户超级管理员权限时,才能调用 Google API。

【问题讨论】:

    标签: google-api google-oauth google-workspace


    【解决方案1】:

    经过一番调查,显然不可能这样做。

    由于某种原因,即使经过身份验证,用户也无法获得自己的自定义角色。因此,我必须创建一个服务帐户并让该帐户模拟具有管理员权限的用户来获取角色分配。

    【讨论】:

      猜你喜欢
      • 2018-07-04
      • 1970-01-01
      • 1970-01-01
      • 2016-12-04
      • 1970-01-01
      • 2017-08-17
      • 2020-11-30
      • 2017-11-12
      • 2012-09-01
      相关资源
      最近更新 更多