Create Docs Add-on to avoid restricted scopes?

33 views
Skip to first unread message

Troy Christmas

unread,
Jul 27, 2019, 6:35:19 AM7/27/19
to google-apps-sc...@googlegroups.com
First, Thanks for creating this group as I missed the G+ Community
Second, Thanks for the Totally Unscripted Videos, especially https://youtu.be/kZ-T581IYSA which addresses this topic.

Goals
  • Watch for changes of Google Docs documents and get notified in my web app
  • Get and Modify documents that meet certain criteria (e.g. contain checkbox glyphs).
  • Avoid the restricted scopes that I would normally use to watch for changes to all Google documents solely from my web app
Idea
  • User authorizes Recommended Scope at my web app (e.g. https://www.googleapis.com/auth/drive.file)
  • Create an Docs add-on that sends the fileID of current document as webhook to my web app based on menu item like "Track Updates" or simply based on onOpen(e) trigger
  • Web app takes fileID to create Drive notifications via watch or Push Notifications.
  • We process the file with our web app based on fileID and recommended scope
Is this possible with add-ons?  If so, any ideas on how to implement?

Can't really use the picker because user may not know which docs meet the criteria until they open them.  This is another reason I thought add-on.

Any help much appreciated.


Dimu Designs

unread,
Jul 27, 2019, 6:57:23 AM7/27/19
to Google Apps Script Community
You're going to have to work around one fairly big issue:

Drive API push notifications sends its payload as HTTP headers (NOT in the POST body). Unfortunately, those headers are not accessible from a GAS Web App's doPost(e) method, so its not a viable option as a web-hook endpoint. You can use a Google Cloud Function as an alternative but that takes you outside of GAS and into the realm of Node.js.


On Saturday, July 27, 2019 at 6:35:19 AM UTC-4, Troy Christmas wrote:
First, Thanks for creating this group as I missed the G+ Community
Second, Thanks for the Totally Unscripted Videos, especially https://youtu.be/kZ-T581IYSA which addresses this topic.

Goals
  • Watch for changes of Google Docs documents and get notified in my web app
  • Get and Modify documents that meet certain criteria (e.g. contain checkbox glyphs).
  • Avoid the restricted scopes that I would normally use to watch for changes to all Google documents solely from my web app
Idea
  • Create an Docs add-on that sends the fileID of current document as webhook to my web app based on menu item like "Track Updates".
  • Web app takes fileID to create Drive notifications via watch or Push Notifications.
  • We process the file with our web app based on fileID and recommended scope
Is this possible with add-ons?  If so, any ideas on how to implement?

Troy Christmas

unread,
Jul 29, 2019, 5:56:52 AM7/29/19
to Google Apps Script Community
Upon further research and recognizing my on folly, to use the drive.file scope, the user will need to expressly grant access file by file.  For my application, the user doesn't know ahead of time, so the file picker is really useless.  What I actually need is an add-on or Chrome extension that can go through the Oauth flow each time a user wants to grant us access to a new Google Doc and I'd love to skip the picker by just passing the file.id which I know is possible with Chrome extension, but not sure if it is with an add-on.

I'll create a separate post about this issue.
Reply all
Reply to author
Forward
0 new messages