How do I restore revoked permissions on a google-apps-script? - google-apps-script

I mistakenly revoked permissions on a google-apps-script that ran on a time trigger on a google spreadsheet from here: https://myaccount.google.com/permissions . I now receive an email that the script fails to run. Going to the spreadsheet and editing the script fails to bring up the script, presumably because of the lack of permissions, but no error is shown, just a blank script editor. I am able to see the trigger to the script (here: https://script.google.com/macros/triggers?id=some_id ), but I am not able to get to the script.
How can I restore or reinstate the permissions to this script?
Or how can I get the code to this script? Where is it stored?

If you simply revoked permissions it will not remove the actual script/coding. So it may not be attached to the spreadsheet you are opening. Perhaps you are opening the wrong spreadsheet, or it is a standalone- If you type type:script into your google drive search it will show all scripts that are not bound to a spreadsheet.
As far as restoring you will just want to run it, once you find it.

I was successful. I'm not sure what did it but: previously I was not able to view the script, looking at the revision history doesn't allow me to get access to the menu and thus I was not able to get at older versions of the script. But making a copy of the spreadsheet then allowed me to view the script again, both in the original and copy of the spreadsheet. Running the script then requests for permission, restoring the permissions!
I really don't know if the lack of access to the script was a temporary condition or required that I make a copy of the spreadsheet, but this was the sequence of events that worked for me.
Thank you #OblongMedulla for making the suggestions.

You can simply go to your Google Profile - Manage Your Google Account - Security - Third Party Apps and revoke the permissions. If you want to use the app again, you'll have to run the script again from appscript and grant the permissions.

Related

I can't create a script on a Google Sheet that I have edit access

We are using Google Workspace in my company and my boss explicitly shared a Google Sheet with me, so he is the owner and I have edit access. I am trying to create an App Script but when I try to access the Script Editor I always get the screen to request access on Google Drive.
Is it still possible to create a script or I am only allowed to create scripts in sheets that I am the owner?
According to Google's documentation on collaborating:
Access to bound scripts
Only users who have permission to edit a container can run its bound script. Collaborators who have only view access cannot open the script editor, although if they make a copy of the parent file, they become the owner of the copy and will be able to see and run a copy of the script.
So I just came across this issue.
Essentially I had my personal account and company account logged in on Google. For some reason, the Script Editor would try and access in with my personal account and when switching to my company account I would get the request access screen.
After logging out of my personal account I was able to create the script normally.

Google Apps Script Document Template Permissions Issue

I added a Doc that has a bunch of custom onOpen() scripts to the template library, when I select the document template and create a new document the scripts no longer work. It seems to be some kind of permissions issue because when I go to edit the script within the new document I'm asked to Allow permission, I select allow, and then the script starts working. I need the permission to be granted by default!
I need the permission to be granted by default!
This is unfortunately not possible :( Please refer Container-bound Scripts > Access to bound scripts.
As it indicates -
Only users who have permission to edit a container can run its bound
script. Collaborators who have only view access cannot open the
script editor, although if they make a copy of the parent file, they
become the owner of the copy and will be able to see and run a copy
of the script.
As a solution perhaps, "...you can force the authorization dialog..." as indicated at Manual authorization scopes for Sheets, Docs, Slides, and Forms.
Hope this helps!

How to use GAS functions in a spreadsheet created by a service account in a team drive?

In my company we use a team drive, where we store a template spreadsheet which our API server copies a lot of times. The spreadsheet contains a few custom Google App Script functions which should be copied as well.
Right now when the API copies the spreadsheet, the scripts stop working in the copy. According to this issue https://issuetracker.google.com/issues/36762799 , service accounts can't execute scripts. However, in a Team Drive there are no owners. I even checked the permissions with Permissions.List from the Drive API and I can see that everyone is an organizer and the API does not allow me to specify another user as an owner, but the scripts still won't work (Error: Please try saving the project again). On the other hand, if I go and copy the generated sheet by hand, scripts execute just fine.
I tried moving everything to an add-on, however to my displeasure, it appears that service account-owned files can't execute add-on scripts as well (if the file is created by the bot, custom function names simply fail to resolve).
Does anyone know of a way to deal with this situation? Is there a more elegant solution besides using an actual account for the copying if that's even possible to do programmatically?

how to stop a google apps script - have already revoked permissions

I ran the Drive Migrator script to try to move some files between 2 google accounts. It failed and kept sending me error emails, so I tried to turn it off by by revoking the Drive Migrator permissions inside my google account settings. Now I get a different email every day, saying that Drive Migrator failed to run because it requires authorization, so it is still running somewhere but I can't find any reference to it in my google account settings. The error email contains a link where I am supposed to be able to configure triggers for the script, but the link just loads a "Forbidden Error 403" page.
Thanks
Open Google Apps Script (can be any script). Remove any triggers that fire the migrator. Revoking the permissions would only cause an error message to be sent out, as the script will try to run due to the trigger. It tries to get through the oAuth and fails, causing you to receive the error.
A trigger is the only thing you need the script to attempt to run. Authorization is needed to actually perform some of the tasks in the script. Heck, some scripts can be run automatically with no authorization whatsoever. Always get rid of any triggers you no longer need.
Try this:
Go here:
https://security.google.com/settings/security/permissions
Scroll down and select "Drive Migrator" then select "Remove".
(It was mentioned in the app reviews)
I went to the respective script and just added /* and */
/*
script here
*/

Google Forms with script transfer of ownership still runs script as previous user

I made a google script in a spreadsheet that responds on form submit. It modifies the files, makes a pdf and emails that pdf to specific people. This was made for someone else and then I transferred ownership. However, the edits to those files and emails sent, still appear under my email. How do I completely transfer the folders and everything in them a different user on the same domain so that they are the ones sending emails and modifying files?
You need to go into the script and add a function that calls ScriptApp.invalidateAuth https://developers.google.com/apps-script/reference/script/script-app#invalidateAuth() then call any function like doGet using the new account to reauthenticate
How do I completely transfer the folders and everything in them a different user on the same domain
When you transferred ownership of your files & folders, everything in them did get transferred.
... so that they are the ones sending emails and modifying files?
However, the TRIGGERS that you had set up previously belong to your account, not to the associated scripts.
You have a couple of options for stopping those triggers from running as you.
Disable specific installable triggers.
If you still have access to the offending script, open it in script editor, go to resources > Current project's triggers, and disable the triggers. Done.
If you don't have access to the script anymore, open the script editor on any of your scripts, go to resources > All your triggers, and disable the triggers if you can identify them. This can be challenging if you use the same names for trigger functions in multiple scripts, as there is no indication here of which script they came from.
De-authorize the offending script.
As Zig's answer describes, if you still have access to the offending script, you can add a function to revoke authorization, and run it from your account.
Alternatively, you can see all scripts that you have authorized, and revoke access directly. Go to your Account Settings page, and select "View all" under Connected apps and services, or use this link.
Select the offending script, then click "Revoke access". Done!
To get the script running under the new owner's account, you need to repeat whatever steps set it up for you, including authorization from their account.