How to determine if the account is a Google apps account?

僤鯓⒐⒋嵵緔 提交于 2019-12-06 04:11:46

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

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

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.

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
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!