We are looking for a way to trigger a function in the add-on in the user's context (authorization) from our web app. We tried using Apps Script Execution API to trigger that. The flow is add-on (apps script) registers the access token in our web app and the web app triggers execution API using the access token. This works for the first time. But the problem is, the access token is valid for only a few minutes. After which the web app is not able to initiate function through execution API due to authorization failure.
Questions:
Is our approach for triggering add-on/ apps script function from another web app in the user's context correct by using execution API?
If so, how do we avoid access token from expiring? Apparently, there is no API in apps script to 'get the refresh token'/ 'refresh the token'. How do we go about refreshing the token so that the token is valid forever (until the user cancels)?
Is there any radically different approach that will help in this case?
I see that add-ons like "PearDeck", "Form Approvals", "Form Publisher" etc are successfully doing this (triggering add-on function from the web app with user's authorization).
Hope to get some expert advice in this forum. Thanks
Used Execution API - with the problem in token getting expired
function prepareToken() {
// send to web app
var token = ScriptApp.getOAuthToken();
URLFetchApp.fetch("url?token="+token);
}
function doSomeWorkFromUserContext() {
// impl here
}
POST https://script.googleapis.com/v1/scripts/{scriptId}:run
Request Header
Authorization: Bearer + {token}
Request Body
{
"function": "doSomeWorkFromUserContext"
}
The function doSomeWorkFromUserContext should get called all the time of invocation but getting Authorization error after some time.