google-apps-scriptoauth-2.0authorize

Why Do I Get Multiple Authorization Requests from Google Sheets Apps Script


After a few minutes of having authorized the Recorded Macros for a Google Sheets Spreadsheet, I am again asked to reauthorized the project to access my account (still using same browser session).

I visited Google account https://myaccount.google.com/permissions to view "Apps with access to your account," I confirmed the Recorded Macros Apps Script was authorized.

As the image below shows, the Recorded Macro appears as "Has access to Google Docs"

Google account user interface Security page shows the Apps that have access to the user account (https://myaccount.google.com/permissions). In this case, the scope is limited to Google Docs

However, when I try to run the Apps Script editor, I get a pop up with the text "Authorization required This project requires your permission to access your data"

Apps Scipt code editor in the background, with modal (i.e., pop up or prompt window) notifying the user that "Authorization required This project requires your permission to access your data"

The content of appsscript.json is below:

{
  "timeZone": "America/Los_Angeles",
  "dependencies": {},
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "sheets": {
    "macros": [
      {
        "menuName": "First Macro",
        "functionName": "FirstMacro"
      },
      {
        "menuName": "ImportHTML",
        "functionName": "ImportHTML"
      }
    ]
  }
}

Why am I required to authorize the same project multiple times?

P.S. Yesterday, I posted this question at the Google Docs forum, but I got no answer, so here I post hoping to get one. Right now, the name of the recorded macro (i.e., Apps Script project name) is "Recorded Macros (Authorized 20230513 Recorded Macro)" Google documentation indicates I post questions related to Apps Script in this forum:


Solution

  • Eveytime we include code that extends the functionality of the Apps Script project, we'll be required to authorized it. This happens as a result of the change in SCOPE for the project.

    When I posted my question, Project OAuth Scopes had changed from 1 Scope Requested

    TO

    Project OAuth Scopes 2 Scopes

    In my case, the change in scope happened as a result of my use of the UrlFetchApp function within the project's code. As stated here, https://developers.google.com/apps-script/guides/services/authorization , "Apps Script determines the authorization scopes (like access your Google Sheets files or Gmail) automatically, based on a scan of the code."

    As the screenshot below illustrates, we can view the current scope by visiting the overview tab of our projects, and scrolling down to the "Project OAuth Scopes" section.

    Apps Script Project Screenshot shows the Overview Tab of the Project which displays details. At the bottom of the image, an arrow points to the OAuth Scopes section.

    The Google Apps Script documentation for the class or service will include information about the scope for it. For example, earlier I mentioned the class UrlFetchApp, and the introduction to the its documentaiton states:

    Within the same document, as we continue to read, we'll find the Authorization specification, which states: