从没有 userinfo.profile 范围的 googleapis 获取用户的组织详细信息(例如标识符 and/or 域)

Get user's organisation details (e.g. idenitifier and/or domain) from googleapis without userinfo.profile scope

我想检索一些描述的标识符,以便我查看用户所属的 Google 组织。此标识符的目的是识别多个用户何时属于同一 Google 组织。

目前我正在做的事情是:

// oauth2 stuff above
const userInfo = await oauth2.userinfo.get({});
const {
  data: { email, hd },
} = userInfo;

此 returns 域 (hd) 但它需要 https://www.googleapis.com/auth/userinfo.profile 范围。此范围请求访问 所有用户的 public 信息,包括性别、姓名、个人资料照片等。

有更好的方法吗?有没有我可以使用的范围,它只要求访问 Google 中的 organisation id 或其他内容?

此标识符对于整个 Gsuite/Workspace 组织必须是唯一的(或者,显然 empty/null 如果它是 gmail 帐户,而不是 Gsuite/Workspace 帐户)。

提前致谢!

如果您请求范围 openid email,则 hd 声明包含在 ID 令牌中,您根本不需要调用 UserInfo 端点。

是的,检查 hd 声明是查明用户帐户是否由 Cloud Identity/Workspace 管理的正确方法。