I'm thinking of storing permissions to users that I locate via cache management. This is kind of what that looks like:
function doGet() {
//upon opening the web page check if user exists:
var cache = CacheService.getUserCache();
var user = Session.getActiveUser().getEmail();
var value = cache.get(user);
//value is null only if user DNE in cache services
if(value === null || JSON.parse(cache.get(user)).access == false){
//instantiate user in cache services with restricted permissions
var permissions ={
"access": false,
};
cache.put(user,JSON.stringify(permissions), 30*60); //key, value, expiration date in seconds
Logger.log(`${user} is unauthorized`)
//open authorization page for uninstantiated users
return HtmlService.createHtmlOutputFromFile('Auth');
}
else if(JSON.parse(cache.get(user)).access == true){
return HtmlService.createHtmlOutputFromFile('Index');
}
}
function newPage(page) {
return HtmlService.createHtmlOutputFromFile(page).getContent()
}
Basically, I'm checking if a user is already in the cache then allocating permissions. Depending on your permissions you are redirected to a different part of the web app.
However, I recently realized that using cache could be a security issue depending on where the cache is stored and the google apps script documentation is not specific about whether the cache is stored on the user or if it is stored on the server. The documentation just says, "Gets the cache instance scoped to the current user and script. User caches are specific to the current user of the script. Use these to store script information that is specific to the current user" in regard to getUserCache()--the property I'm relying on in this script.
The main reason I wanted to use user cache is that I can easily set expiration dates on sessions. Does anyone know a way that I could possibly check where the cache data is stored? Thank you.