Simple recipe for adding per-user authentication for Google APIs to a Coda pack

The authorization URL and the token URL required to configure OAuth2 authentication were somewhat difficult to find in Google’s docs (found here Usando OAuth 2.0 para aplicativos de servidor Web  |  Google Identity Platform  |  Google Developers ), so I thought I would post a template for authenticating Coda packs with Google APIs.

Here is the relevant code without any comments:

pack.setUserAuthentication({
  type: coda.AuthenticationType.OAuth2,
  authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
  tokenUrl: "https://oauth2.googleapis.com/token",
  scopes: [
  ],
  additionalParams: {
    access_type: "offline",
    prompt: "consent",
  },
});
8 Likes

Thanks for sharing! I think you’ll also want to add the following to your auth config:

  additionalParams: {
    access_type: "offline",
    prompt: "consent",
  },

These parameters ensure that you get a refresh token in your Google OAuth2 response, allowing the Pack to automatically refresh it’s access token.

2 Likes

Thanks! Added it to the gist.

Does Google require these prerequisites before using the API with Coda?

Prerequisites

To successfully create your first client application, you must complete the following prerequisites:

  1. Get a Google Account.
  2. Try out Business Profile.
  3. Create a project in the Google API Console.
  4. Request access to the API.

Every Google API is different, but if that’s what the docs says then yes, those will be requirements.