If you are using Parallel process orchestration with HtmlService along with Database abstraction with google apps script you’ll need to know how to work with access tokens for oAuth2. Assuming you’ve used EzyOauth2 patterns to set up your application to be able to refresh tokens automatically, it’s fairly straightforward but you’ll need to be familiar with EzyOauth2 patterns and Datastore driver first.

The profile

First let’s look at the async profile. It’s no different that the others except we are not going to run bigTest directly – first we have to get an access token and inject it, so we need to run dataStoreTest() which will do that, eventually getting round to running bigTest().
{
              "name": "DATASTORE",
              "functionName": "dataStoreTest",
              "skip": false,
              "options": {
                  "driver": "cDriverDataStore",
                  "parameters": {
                      "siloid": "polymerdbab",
                      "dbid": "xliberationdatastore",
                      "peanut": "bruce",
                      "disablecache": 1
                  }
              }
          }

 

dataStoreTest

function dataStoreTest (options, testData ) {
  // this will get an access token and pass it to doTheWork()
  
  return doGetPattern({} , constructConsentScreen, dataStoreTestRun,'googleDatastore',{options:options, data:testData} );
}

This is what htmlService will try to execute. If you recall from EzyOauth2 – taking some pain out of Apps Script API authentication, doGetPattern() simulates the authentication you’d expect with doGet() in a webapp without the need for user intervention by refreshing or reusing an unexpired access token. We also need to pass what doGetPattern() needs to do next – in this case call dataStoreTestRun(), and it has to pass the options and the testData that have been passed on from the profile and from the previous processing stage.

dataStoreTestRun

function dataStoreTestRun (accessToken,pass) {  

   pass.options.parameters.accesstoken = accessToken;
   return bigTest (pass.options , pass.data);
}

 

This will be called by doGetPattern() after it has collected a usable access token. All we need to do is inject it into the options and execute bigTest as normal – just like all the other database back end tests that didn’t need authentication.

And here’s datastore running alongside all the other tests.

For more snippets like this see Google Apps Scripts snippets