Steve
Steve

Reputation: 395

How to use narrower Google Apps Script Authorization Scope when accessing file from own drive

I'm making a google sheets addon and I copy a template sheet from my google drive to the user's current google spreadsheet using:

let ss = SpreadsheetApp.getActive(); 
let source = SpreadsheetApp.openById(TemplateSpreadsheetId); //  <-- gets scope error
let newSheet = source.getSheetByName(mainSheetName).copyTo(ss);

It works when I specify scope https://www.googleapis.com/auth/spreadsheets" in appsscript.json, but is there a way to use a narrower Google Apps Script Authorization Scope ? Other than this I only need @OnlyCurrentDoc or https://www.googleapis.com/auth/spreadsheets.currentonly"

The reason this matters it that users will have to agree that my addon can "See, edit, create, and delete your spreadsheets in Google Drive", which sounds like kind of scary permissions to me.

Upvotes: 1

Views: 1443

Answers (1)

Wicket
Wicket

Reputation: 38140

According to https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#openbyidid

Authorization
Scripts that use this method require authorization with one or more of the following scopes:

I think that the ...currentonly scope only will work when the id is the one of the script container

Upvotes: 1

Related Questions