IMTheNachoMan
IMTheNachoMan

Reputation: 5821

how to pass project authorizations in exported libraries in Google Apps Script

When you reference a library, the pre-approved authorizations on it do not get passed and so the caller script has to re-authorize.

For example, if I:

  1. Create a script with a function that sends an email using my account
  2. Authorize the script with my Google identity so the function can run
  3. Save a version

Then, if someone else reference's it as a library in another script and calls that function, it will require them re-authorize and then it will execute GmailAppunder their Google identity.

Is there a way to make it so caller scripts can call my library functions and have them run under my identity?

Upvotes: 0

Views: 30

Answers (1)

St3ph
St3ph

Reputation: 2288

It is not possible to have a function that run with your credentials, Apps Script always run with user credentials that execute the script. Functions call from a library are just an extension of the current script, that is why user need to authorize the script.

Only way to have a script that run with your credentials is to publish the script as a web app and select to run with your credentials. By this way a user can execute the script as you but you will not to build a custom web interface.

Reference : https://developers.google.com/apps-script/guides/web

You can also imagine to use the OAuth 2 library by setuping a custom authentication system but it is a bit more tricky.

Stéphane

Upvotes: 3

Related Questions