google-drive-api - 如何知道谷歌帐户是否在谷歌应用程序域下?

标签 google-drive-api google-docs

我正在开发一个应用程序,允许用户将他们的云端硬盘文件分享给 friend 。但是谷歌应用账号有问题,比如someone@somadomain.com ,其中文件不能与不在该域下的人共享。尽管可以通过 somedomain.com 的管理员更改共享策略,但我不希望人们通过 Google Apps 帐户使用我的应用程序。

我也检查了这个帖子:How to determine if the account is a Google apps account? .但我不同意检查域以检测帐户类型的想法。因为人们可以使用任何电子邮件地址注册 Google 帐户。我刚刚用我的 Hotmail 注册了一个,someone@hotmail.com ,共享文件时没有域限制。

有人能帮忙吗?谢谢!

最佳答案

假设您包括:

https://www.googleapis.com/auth/userinfo.email

在您的 OAuth 范围内,您可以发出以下请求:
https://www.googleapis.com/oauth2/v2/userinfo

如果它是 Google Apps 帐户,则调用将返回一个“hd”参数(托管域?),并将 Google Apps 域作为它的值。如果是消费者账号,无论是@gmail.com还是潜在的“冲突账号”,都不会返回hd参数。请参阅下面的示例。 admin@jay.powerposters.org 是一个 Google Apps 帐户,而 consumer@jay.powerposters.org 是一个消费者帐户。如果我在 Google Apps 域中创建了一个消费者用户,它将成为一个有冲突的帐户,并且消费者帐户将被推出 @jay.powerposters.org 命名空间,但这还没有发生。

对于 admin@jay.powerposters.org:
GET https://www.googleapis.com/oauth2/v2/userinfo

HTTP/1.1 200 OK
Content-length: 99
X-xss-protection: 1; mode=block
...

{
 "email": "admin@jay.powerposters.org",
 "verified_email": true,
 "hd": "jay.powerposters.org"
}

对于消费者@jay.powerposters.org:
GET https://www.googleapis.com/oauth2/v2/userinfo

HTTP/1.1 200 OK
Content-length: 71
X-xss-protection: 1; mode=block

{
 "email": "consumer@jay.powerposters.org",
 "verified_email": true
}

关于google-drive-api - 如何知道谷歌帐户是否在谷歌应用程序域下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11517551/

相关文章:

google-drive-api - Google Drive Rest API - 如何检查文件是否已更改

sql - 在线协作架构设计(利用谷歌文档?)

android - Google Drive Api 在发布应用程序后停止工作

c# - 如何在 C# 中使用 google drive api 为文件设置自定义文件属性

google-apps-script - 如何通过Google脚本获取Google Docs中的页数?

javascript - google doc如何同时同步两个文档?

javascript - 用图像替换文本 Google 脚本?

google-apps-script - 使用 Google App Script 来自 google drive 的 OCR 图像

google-drive-api - Google Drive 查看器 "document to images"转换 : is there an API for that?

java - 如何在 java 中使用 google drive api 分块下载文件?