I'm working on writing a script to synch email from gmail to another system. One item the script will need is configuration parameters from the user to the other system ( username / password ).
The configuration should only need to be done once for the user and then the script will be set up to run at regular intervals ( probably hourly ).
How can I prompt the user for username & password when they install the add-on and store it so the script can use those values?
Take a look in the docs for user properties service. Store it there its per user.
Note that add-ons dont yet allow time triggers so you cant yet do the 'regular intervals' part with add-ons.
Related
I setup an app script from this help file: https://developers.google.com/gsuite/solutions/vacation-calendar
The default Access setting for users in our domain is to "See all Events" for all domain users - but when I run the sync, it runs without error - picks up only one users event and it doesn't pick up my test 'out of office' event I created.
Does this script need additional perms or do I need to change my sharing settings - I dont know.
I found the answer - so I'm just going to close this particular issue. The script parses a Google Group, I was using the "all hands" special team alias in the group, which does not break out the individual users. I'm going to try and change the script to use the Directory API instead.
I use the google app script in my google spreadsheet document.
The settings of each user of my spreadsheet doc is saved in:
var userProperties = PropertiesService.getUserProperties();.
To save the settings I use
PropertiesService.getUserProperties()setProperties({some properties}, true)
The problem is the first user saves his settings and another users get the settings of the first user using PropertiesService.getUserProperties()
But they should not, they should get own settings.
Do you have any idea how it is possible?
They must be logging in with the same user account for this to happen; a user can only ever access their own user properties. This could be because any triggers were created on your own account (say for form submissions), or web apps were deployed to run as you.
Share a copy of your sheet (andrew#roberts.net) if you would like me to a take a deeper look.
In fact as the support answered me, it is not a bug. I had wrong user properties on handling triggering event.
User properties are private to the user executing the script. However, when you setup an installable onEdit trigger, the code always runs as the user that setup the trigger:
"... runs with the authorization of the user who created the trigger, even if another user with edit access opens the spreadsheet."
https://developers.google.com/apps-script/guides/triggers/installable
Since the code always runs as the same user, it's always accessing the same user properties. In general it's not possible to get the identity of a user if they haven't authorized the script.
I have a list newly creates users in my domain. I want to reset all of their password. But I don't want to do it using admin console. How can I do this using admin SDK and Google App script?
My idea is get a list of user whose password I need to reset, and then assign some random strings to those email id's and update it as their password.
I this possible? If not, is there any better idea? (I have tried using GAM, But I don't want to do it through CSV files each time.)
Resetting a password is possible via the Directory API within the Admin SDK; therefore, you would be able to do this via Apps Script.
Depending how comfortable you are with coding, you might want to use Google Apps Manager to complete this and other tasks. The command to change a password can be found here. These types of commands can be run in bulk by either reading a CSV of all users (can also be created with GAM) or writing a small script to go through a group, OU, etc. and reset only those users.
I am developing a Google Docs Add-on and need to know if the user currently using the add-on has used it before in the current document or any document. I can't figure out which service gives me some kind of unique identifier for the current user that I can use to identify the current user.
The base service's User.getEmail is not good enough as it doesn't give access to the email under certain conditions and is not reliable.
Thoughts on best way to do this?
Unfortunately, there is no such service. Google wants users' personal information to remain private, so AFAIK you won't usually get even user's email, unless your script is written for Google Apps domain and the user is in the same domain as the script's author.
The only thing you can do in the situation is use something like DocumentApp.getActiveDocument().getId() and check if the script was used in this document, but of course this won't give you an idea if user has used your script in other documents or not.
Also you can show a Prompt Dialog to user, asking him to enter email, but of course there is no way you can check if he entered his real email.
Unique user identifier you can get for apps script is Session.getEffectiveUser().getEmail()
This will return the email of user for which the script run. This is better than ActiveUser because if you use trigger EffectiveUser will well return the email of the user who install the script.
I use that for several apps to identify license assignment and it works great.
It looks like the best solution is to roll your own solution using the following to set the userId at an appropriate time:
PropertiesService.getUserProperties().setProperty("userId",<someGeneratedUId>)
then whenever you want to look up if this user is a recognizable user,
var userId = PropertiesServices.getUserProperties().getProperty("userId")
Looks like once set, the UserProperties thus set is available to this particular user (per user) running this add-on everywhere (i.e. all docs, not just the current on) that have this particular add-on enabled/running.
I'll validate this further but seems like this works in my tests.
I have an application Google apps script and i have more than 3 users in this application i want to create an interface for authentication for this application, and according to any user i will open the interface Appropriate to every user.
Some can Help me with an article or with some code please.Thank you.
The approach I used was:
Set up a group "authed" containing the users that are allowed to use the script which allows easy change of authorised people through existing cpanel interface and saves creating a separate store of authorised people
Set the script to run as owner
In the script,
a. Get the active user
b. Get the groups for that user
c. If that group array contains the "authed" group then go ahead otherwise fail gracefully