Retrieve authenticated users email address

1,320 views
Skip to first unread message

DreamDelerium

unread,
Aug 8, 2020, 1:51:05 PM8/8/20
to Google Apps Script Community
Hello everyone,
I am new to Google App Scripts, so if this is obvious, I apologize.  But, I have been searching online and have not found anything.  I have a Google Sheet that has a web app associated.  I want to protect the sheet (only allow myself or designated others in my organizations domain) directly interact with the sheet. But, I want to allow anyone from the public access the site (even if they are not logged into Google).  But, if they are logged into their Google Account (on our domain or in the public) I would like to allow that as a form of authentication to the Google web app, and capture their username.  My Web App is deployed with the following configuration:

1.  Execute the web app as :  me (firstLett...@myorg.com)
2.  Who has access to the app:  Anyone

To test, I login to Google with my personal account.  If I go directly to the Google Sheet, I can view it but it is read only (which is fine).  If I then visit the Google App web page, I can effectively interact with the web page (which reads and writes to the google sheet).  But, when I use the following code, I do not get a response I expect:

  var activeuser= Session.getActiveUser();  //returns nothing
  var userEmail = Session.getEffectiveUser().getEmail(); //returns the username of who the script is executed as (firstLett...@myorg.com), not the personal actually logged into Google.

Is there a way to capture who is actually logged into Google?  But, making sure no one can directly write to the Google Sheet, except for myself or someone I give specific access too?  Hope that makes sense.  If not, please let me know.

Thanks

iBO • App Service

unread,
Aug 13, 2020, 7:29:44 PM8/13/20
to google-apps-sc...@googlegroups.com
Session.getActiveUser().getEmail()

Am Sa., 8. Aug. 2020 um 19:51 Uhr schrieb DreamDelerium
<dreamd...@gmail.com>:
> --
> 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/9c8f31de-a7cc-4396-8e2e-783fdd3e342eo%40googlegroups.com.



--
https://get.ibo.app/signature

--

Reply all
Reply to author
Forward
0 new messages