How to determine if the account is a Google apps a

2019-05-14 02:03发布

I am using the Google documents list api for .net V3(dll version 2.0.1.0). I am using client login authentication as described in this link https://developers.google.com/google-apps/documents-list/#authorizing_requests_with_clientlogin

How can i determine if its a Google apps account or a normal Google account?

Thanks, Bharath

4条回答
我欲成王,谁敢阻挡
2楼-- · 2019-05-14 02:23

I don't think there is a very good way to check if an account is a Google Apps account.

Checking if the email is different than @gmail.com won't work because it is possible to create Google accounts with existing emails addresses.

The only way I'm thinking of is to check the Domain's DNS MX records and see if some service of the domain are served by Google Apps servers (like email served from gmail etc...) but even there you might have to check more than one service because some Google Apps companies deactivate Gmail for instance (or some other service) to use a custom solution instead.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-05-14 02:28

Google consumer accounts are @gmail.com or rarely @googlemail.com, the rest will be Google Apps accounts.

查看更多
Summer. ? 凉城
4楼-- · 2019-05-14 02:42

Assuming you included:

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

in your OAuth scopes, you can make a request to:

https://www.googleapis.com/oauth2/v2/userinfo

If it's a Google Apps account, an "hd" parameter (Hosted Domain?) will be returned by the call with the Google Apps domain as it's value. If it's a consumer account, whether it's @gmail.com or even a potential "conflicting account", the hd parameter will not be returned. See my example below. admin@jay.powerposters.org is a Google Apps Account while consumer@jay.powerposters.org is a consumer account. If I created a consumer user in the Google Apps domain it wouuld become a conflicting account and the consumer account would be pushed out of the @jay.powerposters.org namespace but that hasn't happened yet.

For 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"
}

For consumer@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
}
查看更多
一纸荒年 Trace。
5楼-- · 2019-05-14 02:50

If your goal is to check whether an user has access to a given functionality you can send a request to the Metadata feed and check the <docs:feature> elements.

For instance, a feature with <docs:featureName>upload_any</docs:featureName> indicates that the user can upload any kind of documents:

https://developers.google.com/google-apps/documents-list/#getting_general_information_about_a_users_account

查看更多
登录 后发表回答