Goa services and customization

This describes how to set up new (or examine existing) services using the Goa library as described in Oauth2 for Apps Script in a few lines of code (which you should read first for background).

What is a service ?

A service is a OAuth2 process and properties definition. Many OAuth2 providers have slightly different implementations of OAuth2, and of course have different endpoints. Goa provides the concept of 'a named service', where it already knows how to deal with particular providers, and which can be specified in your package by name, without the need  to research the details of a specific implementation.

A webapp is available to see which services have so far been implemented for Goa. By default it will show all services and their details, but also takes these parameters.

summary=1 - provide a summary of service names
service=servicename - provide details for 'servicename'

An example of a service definition is given below


To see currently supported services, try the webapp . You can also detect all the services from a script by accessing the cGoa.Service.package object.

Custom services


If you have an OAuth2 provider that Goa doesn't know about, you can simply add it to the cGoa.Service.package along with its properties in the script you need to use it in. If you do create a custom service, then post it on the g+ community and I'll add it to the library so others can use it too. 

New definitions can be added like this, and should be the first thing you do before creating the Goa.
cGoa.Service.package.mycustomservice = {
};

and used in credentials package like this.
 cGoa.GoaApp.setPackage (propertyStore ,{ 
    clientId: "yy",               
    clientSecret:"xx",
    scopes : ["all"],
    service: "mycustomservice",
    packageName: "mycustompackage"
 });

Service definition properties.

These are the available properties to define a service.
 property purpose  
 authUrlThe end point from which to get the authentication code
 tokenUrlThe end point at which to exchange the authentication code for an access token
 refreshUrlThe end point at which to exchange a refresh token for an access token. For many services this is the same as the tokenUrl     
 accountType Optional. By default the account type is a regular Oauth web client flow. Aside from the default, the only supported value at the time of writing is 'serviceaccount', which identities that the service shoudl follow the service account flow.    
 accept Optional. Some services need an accept value in the header. For example, Git hub needs accept: "application/json" to be specified here. Generally speaking this is not required. 
 basic Optional. Some services (for example reddit) need the client id and secret to be encoded
 duration Optional Some services allow the lifetime of the access token to be specified. For example, Reddit needs this field to be 'permanent' before it will issue a refresh token.
 defaultDuration Optional. The default lifetime in seconds of service account tokens.

For more like this, see OAuth2 for Apps Script in a few lines of code Why not join our forumfollow the blog or follow me on twitter to ensure you get updates when they are available. 

You want to learn Google Apps Script?

Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, All formats are available from O'ReillyAmazon and all good bookshops. You can also read a preview on O'Reilly

If you prefer Video style learning I also have two courses available. also published by O'Reilly.
Google Apps Script for Developers and Google Apps Script for Beginners.




Comments