1
votes

Background: I'm working within google apps script creating an extension for google sheets. I want to add oAuth.

The Issue: oAuth requires an authorized javascript origin. I get an error when attempting to login using the google sign in button saying uri redirect mismatch and gives a script.googleusercontent.com uri.

What I've tried: I add https://n-z2mpomgsi6mxzkdegvwhypizz4zxupdihnp6udy-0lu-script.googleusercontent.com from my redirect uri mismatch error to the list of authorized javascript origin uris in the developer console because stackoverflow said so. This gets oauth working fine and dandy.

The bigger issue: I go to access my program from another computer. oAuth doesn't work, I check the error and it's using a different script.googleusercontent.com uri in the error.

The Question: What uri can I add to authorized javascript origins to make google happy? (It does not accept wildcards ex. *googleusercontent.com).

1
In order to better understand your situation, could you please provide the relevant parts of the code you're working on? - Iamblichus

1 Answers

0
votes

Google Apps Script handles automatically the OAuth authorization flow, so no need to register a JavaScript redirect URI or even a Client ID in your Google Cloud console, this will be fully managed by Google Apps Script.

Here's a great guide made by the Google on how Authorization Scopes work. But as reading it again, you're right that they don't mention the "authorized javascript origin URIs". That's because Google Apps Script generates one for the developer.

If you open your Google Cloud console, select the project your add-on is tied to and look at your API credentials, you should see within the OAuth 2.0 Client IDs something like the screenshot below:

Apps Script auto-generated credentials

The tooltip on the yellow warning says something like this: "This automatically generated OAuth client ID is required for your project. It can’t be modified."

If you don't see that auto-generated Client ID, there's two reason for that :

  1. You are not in the right project that your add-on is tied to (more on Cloud Platform Projects)
  2. You haven't tied a project to your add-on. Which is not mandatory per se, as Google will automatically generate a default + hidden project with your add-on.