This describes how to customize a consent screen 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 consent screen ?

This is used to get permission to go ahead and authenticate with the OAuth2 provider, and looks like this by default. It is rendered in response to goa.getConsent();

Providing your own consent screen

You can create your own consent screen by simply providing a function that generates the html string.
Here is the default.
It can be overridden like this.

Consent screen parameters

The consent function receives these arguments, which should  be useful in building a consent screen. At a minimum, the consent screen should provide a clickable link to consentUrl, which kicks off the providers OAuth2 dialog.

 property  purpose  
 consentUrl The link to the OAuth2 dialog. Must be rendered as a clickable item on the consent screen.
 redirectUrl Can be shown as a prompt to add to the App Dashboard redirect uri.
 packageName The credentials package name from which this dialog is generated.
 serviceName The service that is being used.
 offline  whether to allow automatic refreshing (true is refreshing is allowed)
Here’s how they map to the default consent screen.

Where to put it?

It’s possible that your script will be executed a couple of times depending on the authentication state at the time you run it. If you are changing the consent screen you need to do it after a goa is instantiated, but before execute() is run. Note that setConsentScreen simply declares a function that is able to generate a consent screen and which is expecting to receive parameters about the authentication account. An example of one is available in goaApp.defaultConsentScreen, and you should use this as your template.
  • Copy goaApp.defaultConsentScreen to your project and call it myConsentScreen.
  • Modify it as required, but be careful to retain the start button and the script info.
  • Override the consent screen with yours using a pattern like the one below
Note – for chaining as above, you’ll need v24 or above of Goa.

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.