MZx5DzNPsYjVyZaR67xXJQai_d-phDA33
Compatibility
Patterns
function doGet(e) { // i need these two var fs = ['script','gasgit'] ; // if we are being called back to get consent then the name of the package will be in the parameters var name = cGoa.GoaApp.getName(e); if(name) { var goa = cGoa.GoaApp.createGoa(name,PropertiesService.getScriptProperties()).execute(e); // renter for consent if (goa.needsConsent()) { return goa.getConsent(); } } // if we get here then we look through each one to see if any more consent is needed for (var i = 0; i < fs.length ; i++ ) { var goa = cGoa.GoaApp.createGoa(fs[i],PropertiesService.getScriptProperties()).execute(); if (goa.needsConsent()) { return goa.getConsent(); } if (!goa.hasToken()) throw 'something went wrong with goa - did you check if consent was needed?'; } return HtmlService.createHtmlOutput ('all tokens created for each of ' + fs.join(',')) .setSandboxMode(HtmlService.SandboxMode.IFRAME); }
Next I needed a new version of getAccessToken() which I had written to pick up tokens inside the gasGit code.
function getAccessToken(packageName) { return cGoa.GoaApp.createGoa(packageName , PropertiesService.getScriptProperties() ).execute().getToken(); }
Finally, I rewrote the setOneTimeProperties – although not needed for this, they may be in the future. Once I run these and provoke a consent dialog, I’ll need to update the redirect URI in the dev console.
function oneTimeSetProperties () { cGoa.GoaApp.setPackage (propertyStore , { clientId : "xxx.apps.googleusercontent.com", clientSecret : "CH1l3wW6lZofc0jX2OR6iBvi", scopes : cGoa.GoaApp.scopesGoogleExpand (['drive','drive.scripts']), service: 'google', packageName: 'script' }); cGoa.GoaApp.setPackage (propertyStore , { clientId : "xxx", clientSecret : "xxx", scopes : [ 'gist', 'repo' ], service: 'github', packageName: 'gasgit' }); }
For more like this, see OAuth2 for Apps Script in a few lines of code
Why not join our forum, follow the blog or follow me on Twitter to ensure you get updates when they are available.