Google Script ~ How to automate authorization for app? - google-apps-script

I've made an app in Google Apps Script to use in an iframe on my site. Problem is I have to go through a bunch of steps every time someone new wants to use the app.
My goal:
What I would like to do is automate the app so it just approves anyone who authorizes it when they're initially prompted. Given that the users initial confirmation is the important part, I don't see why it would be a problem to just have the app allow them in, without them having to wait for me to confirm their confirmation.
The Breakdown:
The permissions settings for the app are as follows:
"Execute the app as:" = "User accessing the web app"
"Who has access to the app:" = "Anyone"
The user must obviously have a Google account to use this app, and they have to authorize the app before they can use it. When they do, an email gets sent to me, I have to find it, open it, and click the "Open sharing settings" link which opens the apps script file, then click "send" on the popup just to allow that one person to use the app.
Many people will be requesting authorization, and I don't want to have to check my gmail every day and manually confirm 5 or 10 new authorizations. That's way too much for me, and too much of a pain for the people using it. Despite having put almost a year into coding this thing, I'd rather not deploy it than bother with that. Yea, I definitely should've scoped this out better before coding the bulk of it.
Potential Solution:
This is a relatively naive guess, but would it work for me to make a second app that runs on a schedule, and opens the initial app's script file in an iframe, using sandbox="allow-same-origin allow-popus" attribute, then maybe use javascript to toggle "send" on the "share with others" pop-up?

Related

How to properly debug WebApps deployed in google scripts?

I have some experience debugging with google app scripts, but I have encountered myself with this problem since I deployed my first WebApp and haven't been able to find a way to solve it.
The webapp can be accessed by anyone who has the link in order to fill a tiny form, and the information is saved on a google sheets file. The thing is, that after the form is filled out it should redirect you to "Page 1" or "Page 2" depending on one of the answers. The main problem is that when the user is redirected to "Page 1" there is no problem, but when the redirection is supposed to be made to "page 2" takes a lot of time and sometimes it just does not do it.
The thing is when I test the page as a common user with my google account logged in (the owner's account of the deployment) , I am able to see details about the errors on the app scripts panel, but when any other user enters the webApp I am not able to see further details about the errors on the app scripts panel. I have some code lines such as:
console.log('Entered 1st step successfully');
to keep track of my process, these logs are indeed registered when I use the WebApp with my google account logged in, but they are not made when the webApp is accessed by any other user, and there are some errors that I just havenĀ“t been able to reproduce, thus corrected them.
Does anyone know how could I properly get the errors information when the users use the WebApp?
I attach an image of the google apps scripts panel which I am referring to.
App scripts panel view
Instead of console.log (which executed on the browser and routes the output to the user running the app), use the Logger class so they show up on the Execution Transcripts on the Google platform.
Hope this helps!

Google web app script keeps asking for users to sign in?

I have created my script and it works great. I have changed the sharing so anybody can view it, but it still asks users to login to their Google account to run the script.
Here is the link: My script
Currently you're web app is set to execute as User accessing the web app. This means they need to sign into a Google account to execute any of the code in your app.
You need to change this setting to: Execute the app as: Me
As well as change Who has access to the app from Anyone to Anyone even anonymous
Example:
The setting can be found by clicking on the cloud icon in the Apps Script IDE's toolbar.
Edit: Added new image to reflect proper settings.
It might be that they've updated the settings to where the least restrictive option is "Anyone" which would still require a log in. This is happening with my Google Workspace for Education account.

Cannot find a Google App Script I deployed as a web app

How can I find a Google App Script web app I deployed and modify it? It does not appear in my drive. Perhaps I didn't save it. Does it persist or disappear eventually? Is there somewhere that list all deployed web apps? If so, I have been unable to find it.
If your webapp is recent, simply replace "exec" at the end of the url with "edit" (without quotes) and you'll get the script editor opened on your script.
(Very old webapp have a different structure but it changed quite a long time ago so I guess you're not concerned with that.)
No. There is nothing like deployed webapps list. if u didn't save, u can't get it back even though you had deployed it. Make a try to open that script with the url available in your browser's history.

How to allow others to access a web app made from a Google Apps Script?

I deployed a web app from a Google Apps Script, but others don't seem to be able to run it.
(It runs fine for me when logged-in to Google)
I keep getting "Request to share" email, even though I set the source script to be "Public on the Web".
"Execute the app as:" is set to "User accessing the web app".
A link to the app is at http://truevis.com/rations
It could be very useful to others, but right now I think that no one else can run it.
The link you show here is the development link , the one that is described as "the last saved version of your code", this link is not shareable ... the one you should give to people is this one :
https://script.google.com/macros/s/AKfycbz1SKJi5HW1r2ZHiYpjedjul-IE4vcB266kdDzDrVCE/exec
it is shown in this popup window
beside that, the sharing properties of the script file is not relevant, you could keep it private.... only the settings in this window are important to determine who has access to your app and how (meaning run as you or as user accessing the app).
You should also keep in mind that users will see the version you have chosen in this same popup window, no matter the changes you could have saved and are using in your .dev version... so think about publishing the right version.
What I did to get it working:
I copied the GS code to a new file, deployed as Web app, then set "Execute the app as:" "me", "Who has access to the app:" "anyone even anonymous".
https://script.google.com/macros/s/AKfycbwPtys8PE8Wda_HS9rvrdftJ0TGbCfMlT5xLlfsNFt9m5uw6qM/exec
I think once you deploy a version with certain permission, it does not work properly if you change the permission for the same version.
Creating a new version seems to solve the problem

GAS: This application was created by another user, not by Google

I have made a script that is running as a 'Apps Script Gadget' in Google Sites. The script has access to my email and calender etc. because I need notifications if someone has used my script.
When I go to the site as "noname" user I get the message "This application was created by another user, not by Google. This application has access to the following personal information: email address." How do I get rid of this, the user is not interested if the script sends me a email or not.
Thank you for any advises.
Same thing happened to me; I commented out all references to the Session object but I still got the popup message.
When I removed the commented code entirely and re-published, everything worked fine. The message about access to the email info was gone.
I guess the google code holds onto an internal library reference even if there is commented code. Does not make much sense to me. But hope this helps.
If your script is not reliant on any of the users' information, I would suggest when deploying the web app to "Execute the app as" me. In the Publish > Deploy As Web App... pop-up, there's a dropdown for this.