Authorize Google App Script before needed - google-chrome

I wrote a Google App Script to be executed in Chrome by an extension without user interaction.
How can I let the user authorize it from the extension's options page?

I assume the script is published to run as the user. If so just provide a link to the script from your options page with a parameter so you know it comes from there.

Related

Prevent Users from Manually Editing the Spreadsheet

I created a web app using Google Apps Script and sharing the link with editor access to other users is needed, otherwise, their input in the web app will not be recorded in the the spreadsheet connected to it.
My worry is if they manually edit the spreadsheet since they have editor access to it.
Is there a way to prevent them from editing the sheet manually?
Deploy the web app with the Execute the app as me option to run it under your account. You do not need to share the spreadsheet or the script with anyone.
See the Web App Demo answer for more information.

Google App Script web app cannot be opened by others

I have deployed a web app using google app script. In my computer everything works fine, the app loads data from a google sheets file and presents in a table. The issue comes when I try to share the deployed link with others. I already changed permissions of the app to "Anyone", "Anyone including anonymous", execute the app always as myself and execute the app as the user and nothing seems to work. When users clic the link they only see a Google sign saying the file can't be reached. Do youy have any suggestions?
The link of my latest implementation is here:https://script.google.com/macros/s/AKfycbwhBuYsrRVabtSm983UWYCtRQ3KRn9ATmp0r7wGFVasMWQUjpf7L6h2qUIDRA5SFEg/exec
Thanks.
It's very likely that you set the web app deployment to be run as the user accessing the web app but the spreadsheet is not shared with anyone on the web / anyone with the link.
To fix this change the spreadsheet sharing settings accordingly.
Please be aware that once the users access the spreadsheet through your web app they will be able to find the spreadsheet in Google Drive and in Google Sheets > Shared with me.
I have a same issue with you Rivaa.
What I did is:
https://script.google.com/home > let the others check on 'Shared With Me'
give ur email via Lastpass in order to avoid show your password
I hope these will help you more or less.

Google docs scripts asks for permission everytime

So my question i have a google docs template which has a script with certain autofill criteria. After you click on use this template fine you get a file and when you run the script everytime is asks for permission to access the certain things google needs to identify you, it basically acts like its a new app everytime you create a new file from the template.
Is their a way of setting it won't ask for permission everytime?
If you have a document bound script in your document, and if you will make a copy of that document and run the script, google app script will ask permission every time. Copying the document with script acts as if you have created a new script file and now script will ask permission on its first run.
Possible solution
You can publish your script as google document add-on. If you don't want to expose it publicly, you can also publish the add-on privately which only you or someone you will share with, can use.
check out the documentations
https://developers.google.com/apps-script/add-ons/publish#development_checklist
https://developers.google.com/apps-script/add-ons/domain-wide#publishing_for_domain-wide_installation
Publishing the add-on will bind your add-on to every document for google apps.

Share a Google App Script to other users - permission requested & authorize script

I've created a spreadsheet with some GAS behind it that opens a form with some inputs, and now I need to deploy the webapp and share it to some other users. The problem is that when the other users try to open the spreadsheet (shared in Google Drive), they get this error message:
I've already tried to:
Share the spreadsheet to the user/s (Adding the user/s email address with permission Can edit)
Deploy the webapp settings with the following settings:
As you can see, the setting screen reports "You need to authorize the script before distributing the URL".
How can I authorize the script? I can't find a way to do that. Do you know if there's another way to share and let other users run the script?
Since you selected to execute the app as you, you need to authorize this script first.
Just select method doGet and press run in the editor, you will get the chance to authorize.
The problem is you are mixing web app with ui dialog on a sheet.
The webapp is accesed from the webapp url (given when you publish the webapp).
The ui dialog is a window shown on top of the spreadsheet.
You want to use webapp, follow the tutorial for that. Publish it to be accesed from the domain if all users are in the same gapps domain. Else use public anonymous.
Run doGet before publish to authorize. Its also possible to do the other ui-on-sheet but you need more steps for each user to authorize.
You need to manually verify that your script has access to the document.
Add a function to your script that accesses the document:
function doInstall() {
var mysheet = SpreadsheetApp.openById('x4535khxxhidh...');
}
In script-editor select: Run->doInstall (Or what ever you call your function) when you should be asked to verify that the script is authorized to access the document.
The following worked for me:
Go to «Publish»
Click on «Deploy as web app»
Click on «Disable web app» (in case you have published it already)
Execute the Script clicking on «Run»
Authorize the Script and grant permissions with your account
Again, go to «Publish» and click on «Deploy as web app»
Add another «Project version» (in case you have published it already)
Change «Who has access to the app:» to «Anyone, even anonymous» as needed

Delay the Authorization Dialog with GAS Ui Service

Is there a way to delay the Authorization Dialog in a stand alone Google Apps Script?
I have a public script that needs to be granted several permissions from the active Google user. I want to tell the user how the script works before asking for all those permissions.
It is not obvious why I need access to all the services, so this dialog looks scary :
https://developers.google.com/apps-script/scripts_google_accounts#grantingAccess
My script is a "web app' with the UI Service so the first thing to be displayed comes from doGet(), but the permission dialog opens first. Isn't there a way to delay the dialog until the permission is actually needed ?
One possible way would be to call the script from a dedicated website I suppose, but that's not simple.
One workaround is to have two web apps:
The first is an 'intro' web app that runs using your account, so it doesn't prompt the user.
Then, you redirect them to a second web app that runs using their account, which will prompt them.