2
votes

I'm trying to execute a Google Apps Script from an event on my Chrome extension. While it works great, when ran for the first time by a new user, the apps script requires for the user to give it authorization before it can execute. The problem is when running the script from the extension the user doesn't see the authorization request so nothing happens. They would have to manually run the script first on their web browser and after that the extension starts working.

My question is, why is the script asking for authorization if it's deployed for "anyone" to access it. The Google sheet is also published and editable by anybody with a link so no authorization is required to edit it.

1

1 Answers

3
votes

...no authorization is required to edit it

Fine distinction here... no PERMISSION is needed for the shared spreadsheet, however editors must still be AUTHORIZED by the service. For the Sheets UI, being logged in to your Google account is sufficient authorization.

Google Apps Script kicks off the authorization cycle when a script does anything on behalf of a user, that would normally require being logged in.

The spreadsheet may be public, and the script set for "anyone" to access it, but from your description I'd assume that the script is also set to run as "User accessing the web app". It's that choice which is driving the authorization cycle, just as it did when you first tested your script in the editor.

If the script is using any service that requires authorization (e.g. SpreadsheetService), then authorization is required.

If you instead published it to run as "Me", then only you would ever need to provide authorization. Further, if you also change its accessibility to "Anyone, including anonymous", then it won't even need a Google account login. (If you didn't use any services requiring authorization, you'd also avoid the authorization step.)