Google Apps Script – Register Application and Retrieve Client ID and Secret for OAuth

google-apps-script

How do I register an Apps Script project and get the Client Secret for oAuth, and set the callback URL?

Best Answer

These are instructions for getting the client ID and secret for oAuth.

This explains the process of navigating the Cloud Platform and getting your Apps Script project information including the client ID and secret.

An Apps Script project is initially given a "default" Google Cloud Project, but you will need to create a "standard" Google Cloud Project, and then associate the Apps Script project with the Google Cloud Project. To create a "standard" Google Cloud Project, you must first open the Google Cloud Platform dashboard at:

Google Cloud Platform

Then you need to create a new Cloud Platform Project, get the Cloud Platform Project id number, and add it to the Apps Script Project.

First go to IAM & admin, and choose "Manage resources" Click "Create Project"

Create a project, and get the id number. Go back to the Apps Script code editor, and open the Resources menu. Enter the id number and associate it with the Apps Script project.

  • In the "Resources" menu, choose the "Cloud Platform Project" item.

Cloud Platform Project

Dialog comes up:

Developers Console Dialog

Click Blue Link. Developers Console comes up. Navigate to Credentials.

Navigate to Credentials

In the Credentials page, click on either the Name or the "Edit OAuth Client" (pencil) icon.

Click on Name in Credentials

Get the client ID and the client secret. You will need this for the oAuth authorization.

Client ID and Secret

You must also enter a Redirect URI:

Quote from Eric Koleda's apps-script-oauth2: Eric Koleda's apps-script-oauth2

Before you can start authenticating against an OAuth2 provider, you usually need to register your application and retrieve the client ID and secret. Often these registration screens require you to enter a "Redirect URI", which is the URL that users will be redirected to after they've authorized the token. For this library (and the Apps Script functionality in general) the URL will always be in the following format:

https://script.google.com/macros/d/{PROJECT KEY}/usercallback