I have a working GAS web application that is deployed
- execute as - me
- who has access - anyone
now I need to separate data that the users are using, storing, accessing. I was thinking of using Google Sign-In but then I thought that I might somehow get user's info when they are logged into their Google account if I deploy with the who has access option set to Anyone with Google account. But I am not able to find anywhere how or if even I am able to get any details of the logged in user.
The only info that is related is this SO question Get user info when someone runs Google Apps Script web app as me . The solutions proposed https://stackoverflow.com/a/59974388/250422 seemed to me too complex if I can get details of the logged user in my GAS code.
Or is there any simple way how to protect my GAS web application with login? I want to save user related data to a dedicated spreadsheet for that particular user. So I need to somehow identify the user.
UPDATE To be clear what I want to achieve
- have a GAS web application with login authentication
- each user of such application got separate Google spreadsheet file stored under my account or somewhere where I got access to it but NOT the end user
- preferably I would use an existing facility for the login part
UPDATE2 as requested the code that I am currently using is
function doGet() {
Logger.log("let us start");
var htmlTemplate = HtmlService.createTemplateFromFile('index');
// htmlTemplate.dataFromServerTemplate = { fromServer: zzlib.settings.toHTML};
var htmlOutput = htmlTemplate.evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
var email = Session.getActiveUser().getEmail();
Logger.log(email);
tmplibX.saveFile(email);
HtmlService.createTemplateFromFile('index').evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) //SAMEORIGIN
return htmlOutput;
}
and the tmplibX.saveFile(email); looks like
function saveFile(fileName){
console.log("from library");
Logger.log("from library");
console.log(fileName);
var fileName=Session.getActiveUser().getEmail();
console.log(fileName);
DriveApp.createFile("FROM-LIB-"+fileName, 'Hello, world!');
console.log("finished");
}