This describes how to migrate from cEzyOauth2 while using the Goa library as described in Oauth2 for Apps Script in a few lines of code (which you should read first for background).
The library, cGoa, is available under this project key.
MZx5DzNPsYjVyZaR67xXJQai_d-phDA33
Page Content
hide
Compatibility
Goa is compatible with cEzyOauth2, and can use existing credentials and tokens that have been created by cEzyOauth2. The redirect URI will have changed and will need to be updated in the app dashboard as advised by the consent dialog when you get one.
Patterns
The patterns for Goa are much simpler. I converted gasGit, which needs 2 token flows (one for drive, another for github) in a few minutes. There was no need to reinitialize the credentials since they are the same structure. After deleting all the ezyoauth2 stuff, the doGet pattern became. For more details on multiple Oauth2 see Multiple oAuth2 authentication packages
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
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); } |
1 2 3 |
function getAccessToken(packageName) { return cGoa.GoaApp.createGoa(packageName , PropertiesService.getScriptProperties() ).execute().getToken(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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.