ReDriveApp, a replacement for DriveApp that doesn't require the full '/drive' scope

164 views
Skip to first unread message

Dave Abouav

unread,
Feb 10, 2024, 12:35:53 PM2/10/24
to Google Apps Script Community
Hi All,

I wanted to share with everyone here ReDriveApp, my open-source replacement for Apps Script's DriveApp service that doesn't require the full '/drive' OAuth scope. Read on for more information about how it can benefit your Apps Script projects. 

*Note that I work at Google, but this is not a Google product or project.*


The built-in DriveApp service is an easy and powerful way to interact with Google Drive in your Google Apps Script projects, which is why so many developers make use of it. It's one downside is that it forces your project to use the full '/drive' OAuth scope, which is a "Restricted" scope. Restricted scopes can raise concerns from end-users and Workspace admins based on the extensive level of access they request (i.e. full access to all of a user's files in Google Drive). They also require additional reviews from Google and/or 3rd-party security auditors if you wish to publish your Apps Script project as a publicly available app (Add-on, Chat App, etc). In many cases though, projects don't really need the full /drive scope for common tasks, and the Recommended /drive.file scope is sufficient. This allows your project to create new files, and open existing files if authorized by the end-user via the Drive Picker. Using it also avoids the aforementioned security review, and is less alarming to users when authorizing your app.

While it's possible to access the Drive API with a more limited scope by using the Drive "Advanced Service" in Apps Script, this can still be daunting and confusing to less experienced developers. It can also be a real pain to go back over an existing project that used DriveApp an refactor it to use the Drive Advanced Service. To that end, I create ReDriveApp, an open-sourced replacement for DriveApp that doesn't require the full /drive OAuth scope. Just paste the contents of ReDriveApp.gs into a new file in your Apps Script project, and then replace all your references to "DriveApp" with "ReDriveApp". Finally, modify your project's manifest file to use only the '/drive.file' scope (vs full '/drive' scope), and you're all set!

Please note that it's still a work-in-progress, as there are a very large number of methods to implement to achieve full parity with DriveApp. But it already has the most common DriveApp methods (i.e. getFileById(), createFile() ), as well as equivalent classes and methods for the native Apps Script classes: File, FileIterator, Folder, FolderIterator, and User. And I'll happily accept contributions to help built it out more.

Please give it a try in your project and let other developers know who may benefit from its use!

Best,
Dave

Brett Grear

unread,
Feb 11, 2024, 5:09:40 AM2/11/24
to Google Apps Script Community
Love it. Starred on github
Reply all
Reply to author
Forward
0 new messages