2

I recently changed the email addresses for several distribution groups, and I want to help users remove the OLD addresses from their contact list so they don't accidentally send emails into the ether. The Admin SDK does not provide access to other users' contacts, so I have made a script (EDIT: deployed as a web app) that runs as the user at the keyboard to delete the relevant groups. However, when the page loads, they are automatically prompted for authorization.

To avoid confusion, I would like to show a message of explanation before this occurs. To do this, I need to detect whether the user has already granted authorization for the required actions.

I have seen a similar behavior in an older add on. In that case, the author used ScriptProperties.getProperty('scriptAuthorized'), but this is now deprecated. Anyone know how to accomplish this?

Charlie Patton
  • 435
  • 2
  • 12
  • I have not tested this but you can try this [`PropertiesService.getScriptProperties()`](https://developers.google.com/apps-script/reference/properties/properties) under `Properties` Class. [`getScriptProperties()`](https://developers.google.com/apps-script/reference/properties/properties-service#getscriptproperties) gets a property store that all users can access, but only within this script. Hope this helps. – Mr.Rebot Jun 16 '16 at 16:23
  • @Mr.Rebot - It looks like the `PropertiesService` is for storing properties from your script. Doesn't let us access the authorization information. – Charlie Patton Jun 16 '16 at 17:16

1 Answers1

0

I found a workaround, which I believe may be the only way to actually address this issue.

Remember, the web app was set to run as the user at the keyboard rather than as me. This was required so that the app could access the user's contacts. One consequence of this is that even the doGet(e) function REQUIRES AUTHORIZATION. That means that there was no way to display ANYTHING without authorization. This rendered my original intent of detecting the script authorization moot. Even if it didn't, I believe that even the action of checking authorization requires authorization.

My solution to this problem was to create a second web app to use as a portal for the real web app. This portal app runs as ME instead of the user at the keyboard, therefore doesn't require authorization to load. I can't detect whether they need authorization, but I can at least present them with information that they MIGHT encounter the dialog.

I've included the (very simple) html for the portal:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
  <p>
    This tool will erase all of the old, irrelevant contact groups. <br>
    When you click below, you may be prompted to authorize this app. Please do so.
  </p>

  <div>
     <a href='https://link.to.script'> <input type='button' value='Click here to begin'></a>
  </div>

  </body>
</html>

I think I'll be using this strategy for a few other purposes as well, so I'm leveraging the solution found in this discussion to serve multiple html pages from one web app: Linking to another HTML Page in Google Apps Script

Community
  • 1
  • 1
Charlie Patton
  • 435
  • 2
  • 12