Goa knows how to talk to a number of different Oauth2 providers using various flavours and varieties of OAuth flow.

Goa library is available with this key.

MZx5DzNPsYjVyZaR67xXJQai_d-phDA33

You just have to specify the service in your oneoff function to set up your credentials, as in the example below, as Goa already knows the parameters for registered services.

function oneOffClassy (){   

   cGoa.GoaApp.setPackage (PropertiesService.getScriptProperties() , {
    clientId:'Z......d',
    clientSecret:'A....dE',
    packageName: 'classy',
    service:'classy'
  });
}

Custom service

If you want to use Goa for a service that’s not already known, you can use a custom service instead. A custom credential package for equivalent to example above would look like this, where the service is set to “custom” and serviceParameters contains information describing how to make the OAuth flow.

function oneOffClassyCustom (){   
   cGoa.GoaApp.setPackage (PropertiesService.getScriptProperties() , {
    clientId:'Z......d',
    clientSecret:'A....dE',
    packageName: 'classy-custom',
    service:'custom',
    serviceParameters: {
      authUrl : "https://api.classy.org/oauth2/auth",
      tokenUrl: "https://api.classy.org/oauth2/auth",
      refreshUrl: "https://api.classy.org/oauth2/auth",
      accountType:"credential"
    }
  });
  }

ServiceParameters

These are the services currently known by Goa. (To check the latest version of this you can use Logger.log (JSON.stringify(cGoa.Service.package));)

service.package = {
    "google_service": {
      authUrl : "https://www.googleapis.com/oauth2/v3/token",
      tokenUrl: "https://www.googleapis.com/oauth2/v3/token",
      defaultDuration:600,
      accountType:'serviceaccount',
      checkUrl:"https://www.googleapis.com/oauth2/v1/tokeninfo?access_token="
    },
    "google": {
      authUrl : "https://accounts.google.com/o/oauth2/auth",
      tokenUrl: "https://accounts.google.com/o/oauth2/token",
      refreshUrl: "https://accounts.google.com/o/oauth2/token",
      checkUrl: "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token="
    },
    "linkedin": {
      authUrl : "https://www.linkedin.com/uas/oauth2/authorization",
      tokenUrl: "https://www.linkedin.com/uas/oauth2/accessToken",
      refreshUrl: "https://www.linkedin.com/uas/oauth2/authorization" 
    },
    "soundcloud": {
      authUrl : "https://soundcloud.com/connect",
      tokenUrl: "https://api.soundcloud.com/oauth2/token",
      refreshUrl: "https://api.soundcloud.com/oauth2/token" 
    },
    "podio": {
      authUrl : "https://podio.com/oauth/authorize",
      tokenUrl: "https://podio.com/oauth/token",
      refreshUrl: "https://podio.com/oauth/token" 
    },
    "shoeboxed": {
      authUrl : "https://id.shoeboxed.com/oauth/authorize",
      tokenUrl: "https://id.shoeboxed.com/oauth/token",
      refreshUrl: "https://id.shoeboxed.com/oauth/token" 
    },
    "github": {
      authUrl : "https://github.com/login/oauth/authorize",
      tokenUrl: "https://github.com/login/oauth/access_token",
      refreshUrl: "https://github.com/login/oauth/access_token",
      accept: "application/json"
    },  
    "reddit": {
      authUrl : "https://ssl.reddit.com/api/v1/authorize",
      tokenUrl: "https://ssl.reddit.com/api/v1/access_token",
      refreshUrl: "https://ssl.reddit.com/api/v1/access_token",
      basic:true,
      duration:'permanent'
    },
    "asana": {
      authUrl : "https://app.asana.com/-/oauth_authorize",
      tokenUrl: "https://app.asana.com/-/oauth_token",
      refreshUrl: "https://app.asana.com/-/oauth_token",
    },
    "live": {
      authUrl : "https://login.live.com/oauth20_authorize.srf",
      tokenUrl: "https://login.live.com/oauth20_token.srf",
      refreshUrl: "https://login.live.com/oauth20_token.srf",
    },
    "paypal_sandbox": {
      authUrl : "https://api.sandbox.paypal.com/v1/oauth2/token",
      tokenUrl: "https://api.sandbox.paypal.com/v1/oauth2/token",
      refreshUrl: "https://api.sandbox.paypal.com/v1/oauth2/token",
      basic:true,
      accountType:"credential",
      accept: "application/json"
    },
    "paypal_live": {
      authUrl : "https://api.paypal.com/v1/oauth2/token",
      tokenUrl: "https://api.paypal.com/v1/oauth2/token",
      refreshUrl: "https://api.paypal.com/v1/oauth2/token",
      basic:true,
      accountType:"credential",
      accept: "application/json"
    },
    classy: {
      authUrl : "https://api.classy.org/oauth2/auth",
      tokenUrl: "https://api.classy.org/oauth2/auth",
      refreshUrl: "https://api.classy.org/oauth2/auth",
      accountType:"credential"
    },
    firebase: {
      accountType:'firebase'
    }
	};

Not all properties are required for each service as each implementation has its own little foible. Any trouble with implementing new ones – let me know. If you create a custom flow and would like it included in Goa (and make it available to all), then ping me and I’ll add it to service list.

For more like this, see Google Apps Scripts Snippets
Why not join our forum, follow the blog or follow me on twitter to ensure you get updates when they are available.