Keep authorization when making a copy of a spreadsheet

1,358 views
Skip to first unread message

Cedric Greiten

unread,
Jun 6, 2022, 3:15:12 PM6/6/22
to Google Apps Script Community
Hey everybody,

let's say I have a spreadsheet "Z" and the associated apps script project "Z Script". "Z Script" requires at least one authorization scope (such as "https://www.googleapis.com/auth/spreadsheets" or "https://www.googleapis.com/auth/drive.readonly"). Now when I run a function "f" in "Z script" from "Z" (for example through a menu), I get prompted to authorize the project, which makes sense.

However, if I now make a copy of "Z", calling it "Copy of Z", and then try to run "f" from "Copy of Z", I am prompted to authorize the code again. I would like to prevent that i.e. would like "Copy of Z" to remember that it was already authorized in "Z".

Is there any way to do so?

I have tried creating a seperate Google Cloud project and entering the required oauth scopes under "Your sensitive scopes" while editing the project from the OAuth consent screen, but that did not help.

Cheers!

CBMServices Web

unread,
Jun 6, 2022, 5:23:05 PM6/6/22
to google-apps-sc...@googlegroups.com
Not that I know. The copy is now a separate spreadsheet and must be authorized separately.


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/d4b0aac6-6c53-44b3-be76-01ee5c678319n%40googlegroups.com.

Cedric Greiten

unread,
Jun 6, 2022, 5:25:36 PM6/6/22
to Google Apps Script Community
What if I put all the code in a separate library and had the user authorize that once instead of the spreadsheets?

Michael O'Shaughnessy

unread,
Jun 6, 2022, 5:33:22 PM6/6/22
to google-apps-sc...@googlegroups.com
I agree with CBMServices...  It would be verging on "privacy protection" if what you want to happen would happen.  The script is "bound" to the spreadsheet.  So when you make a copy, the script gets copied as well and is SEPARATE from the original.

Now with that said... You may be able to accomplish more "streamlined" permissions if you use a library.  Put code that you want to be accessible from all spreadsheets into a library and add the library to the spreadsheet.

Just a thought.

CBMServices Web

unread,
Jun 6, 2022, 5:37:54 PM6/6/22
to google-apps-sc...@googlegroups.com
It depends where the trigger is. And in this case, the trigger will always be in the new spreadsheet, so you will have to re-authorize it.

Cedric Greiten

unread,
Jun 7, 2022, 5:15:04 AM6/7/22
to Google Apps Script Community
Thanks for you replies!

I tried moving the code into a separate library, but that did not help. I'm starting to think that creating an addon might be the only solution to this. I'll start doing some research if an addon could help with this problem while not overcomplicating things. If any one of you have some tips regarding that, I'd love to hear them.

Cheers!

Max Yusupov

unread,
Jul 29, 2023, 9:04:52 AM7/29/23
to Google Apps Script Community

in google sheets the author property is not safe unless you use some technics in library each sheet should has its own library it is little takes time instead of SpreadsheatApp.getactiveSpreadsheet() you do  SpreadsheatApp.openById('your_sheet_id') than th scripts doesnt work for that duplicated sheet but it effect to those from whom he copied than there is pasword protection funtion together and delete all sheet function that works together.
)) any way google sheets security is bit sucks for my vision,  coz there is may be written formulas and button or triggers, if they want just sheet fomulas they wont authorize be4 copying, so they still go to appsscript than delete all call library function to use sheet itself formulas. i hope by some times that they will realize that this should be corrected by cloud service!
понедельник, 6 июня 2022 г. в 17:33:22 UTC-4, Michael O'Shaughnessy:
Reply all
Reply to author
Forward
0 new messages