I searched and couldn't find any topic like this, to my surprise. I was convinced someone would have asked about this by now.Any way, does anyone on this forum have a working implementation that helps developer to distinguish between individual vs enterprise users?
If so, do you mind sharing it?
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a362944c-de24-4e06-abca-79636287738b%40googlegroups.com.
On Fri, Aug 23, 2019 at 11:48 AM Andrew A. <chis...@gmail.com> wrote:
I searched and couldn't find any topic like this, to my surprise. I was convinced someone would have asked about this by now.--Any way, does anyone on this forum have a working implementation that helps developer to distinguish between individual vs enterprise users?If so, do you mind sharing it?
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.
function myFunction(){
var a = Sessions.getEffectiveUser().getEmail();
var res = a.split("@")[1];
if( res == "gmail.com"){
// Do something;
} else {
// Do another thing;
}
}
var domainName,param,response,url,user,userinfo;
url = "https://www.googleapis.com/oauth2/v2/userinfo";
user = Session.getEffectiveUser().getEmail();
//The above "user" variable is not used but the above line is to be certain that the permission gets approved -
//If the scope was not set in the manifest file and there was no other line of code to prompt the user to authorize
//that permission- then the code would fail - that why the above line of code is there to cause the authorization process
//to ask the user to authorize this scope
param = {
"method" : "get",
"headers" : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
"muteHttpExceptions":true,
};
response = UrlFetchApp.fetch(url, param).getContentText();
userinfo = JSON.parse(response);
//Logger.log(JSON.stringify(userinfo,null,2));
if (userinfo) {
domainName = userinfo.hd ? userinfo.hd : false;
}
{
"id": "10",
"email": "na...@domainname.com",
"verified_email": true,
"name": "First Last",
"given_name": "First",
"family_name": "Last",
"picture": "https://lh3.googleusercontent.com/a-/",
"hd": "domainname.com"
}
{
id=1...2,
verified_email=true,
email=o...@gmail.com,
picture=https://lh3.googleusercontent.com/a-/...
}
Ok... I'll depend on your experience then.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/354efe8c-05be-429d-b3ce-453e52985306%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CA%2B89ScwBMi4uQ6Fo4PnaVnkt_cmA1fJxHuGFMRCKtytnx88qVg%40mail.gmail.com.