I am looking for a simple way to check programmatically if user authorization is required to run a Google Apps Script. I am calling the script from a Chrome Extension using HTTP GET and would like to show the Google's authorization request page only when required (typically on user's first run on the extension).
Some details:
Currently I make a "GET" XMLHttpRequest using withCredentials=true.
The request url format is 'https://script.google.com/macros/s/<..ID..>/exec?<..my params..>' which executes the doGet(e) function inside the script.
When the GAS is authorized, my doGet() returns a JSON text (which my Chrome Extension parses).
When the GAS is not authorized, doGet() returns an HTML text starting with "Authorization needed ..." and xhr.status stays 200.
I can try parsing this HTML string to detect if authorization is required but that seems fragile so I am looking for a better way.