I wrote a script that needs to store the username and password of a specific user in order to be used by a trigger on a weekly basis. I am storing these credentials as script properties so all users within a project can run the app as long as User 1 adds their credentials
For example: My code is asking via ui to enter a username and password and stores the response as
let properties = PropertiesService.getScriptProperties();
let username = properties.getProperty('username');
let password = properties.getProperty('password');
let usernamePrompt = ui.prompt("User Credentials","Enter username", ui.ButtonSet.OK_CANCEL);
username = usernamePrompt.getResponseText();
let passPrompt = ui.prompt("User Credentials",'Enter Password',ui.ButtonSet.OK_CANCEL);
password = passPrompt.getResponseText();
properties.setProperty('username',username);
properties.setProperty('password', password);
Question 1:
User 1 downloads the app and installs it enters their credentials. User 1, user 2, user 3 etc can use the app within User 1’s project without any issues because User 1 credentials are stored.
However, if User 2 downloads the same add on, will they be prompted to enter their own credentials or will User 1 credentials be saved to User 2’s project?
Question 2:
If User 1 downloads and installs the app into project 1, and adds their credentials into project 1, will these credentials be available if User 1 decides to use this app in project 2? Or will they be prompted to enter credentials again into project 2?
Let’s start by clarifying that Google Apps Script add-ons are not downloaded. They are installed.
The Properties Service has three property stores: Script, Document and User.
The properties of the Script store are always available. The code included in the question uses this store.
The properties of the Document store are available only for the document in which they were created. Any user accessing the document might retrieve the document properties, but only by using the add-on to create them.
The properties of the User store are only available for the effective user who created them, but only by using the add-on to create them.
For further details see https://developers.google.com/apps-script/reference/properties.