68
votes

When making an auth request to the Google API (gapi), it's returning false on the checkOrigin.

I have removed any client id's or anything that would link directly to my account and replaced it with a regex indicating what the data is for reference.

Url: https://accounts.google.com/o/oauth2/iframerpc?action=checkOrigin&origin=https%3A%2F%2Flocal.tools&client_id=(\d{21})

My origin url is a local url, which is https://local.tools

Result: {valid: false}

I'm using the example found here without deviation (except for replacing clientid with my 21 digit clientid): https://ga-dev-tools.appspot.com/embed-api/third-party-visualizations/

The items I'm trying to display show up nicely on the demo site, but aren't getting past the Not valid origin for the client error on my local.tools site.

14
and "local.tools" is deffo configured in the API console and your local server is running on port 80? Try editing your /etc/hosts to point your demo site URL to 127.0.0.1 and see what happens. - pinoyyid
Nothing good would happen because my development environment is not on 127.0.0.1. It also doesn't matter what port it's running on. It can be used on other ports besides port 80. - Francis Lewis
Google API authentication: Not valid origin for the client. --- It might be in case, while you are using same email id for creating client id and for sign-in through webpage - Sahil Mujawar

14 Answers

160
votes

Clear your browser cache. Started getting this error in Chrome and then I created a new client id and was still getting the issue. Opened firefox and it worked, so I cleared the cache on Chrome and it started working.

72
votes

I received the same console error message when working with this example: https://developers.google.com/analytics/devguides/reporting/embed/v1/getting-started

The documentation says not to overlook two critical steps ("As you go through the instructions, it's important that you not overlook these two critical steps: Enable the Analytics API [&] Set the correct origins"), but does not clearly state WHERE to set the correct origins.

Since the client ID I had was not working, I created a new project and a new client ID. The new project may not have been necessary, but I'm retaining (and using) it.

Here's what worked:

During creation of the credentials, you will see a section called "Restrictions Enter JavaScript origins, redirect URIs, or both". This is where you can enter your origins.

Save and copy your client ID (and secret).

My script worked after I created the new OAUTH credential, assigned the origin, and used the newly generated client ID following this process.

21
votes

try clear caches and then hard reload, i had same error but when i tried to run on incognito browser in chrome it worked.

13
votes

Credentials do not work if API is not enabled. In my case the next steps were needed:

  1. Go to https://console.developers.google.com/apis/library
  2. Enter 'People'
  3. From the result choose 'Google People API'
  4. Click 'Enable'
12
votes

Key Point: Add both http://localhost and http://localhost:port_number to the Authorized JavaScript origins box for local tests or development.

10
votes

For me - I just went here:

https://console.developers.google.com/apis/credentials

Then chose the right project; then choose the credential with the same ID shown in your console error message. When editing the credentials you can add multiple origins to the white list.

7
votes

Creating new oauth credentials worked for me

3
votes

clearing the cache works for me.

for React developers try to restart the project otherwise it will show the same error again and again.

2
votes

Clearing the cache on chrome works!

Please find the steps below to clear the cache.

  1. Open dev tools (Right-click on the page and select inspect/ press F12)
  2. Right-click on the chrome reload button while the dev tool is opened. (You will find the option to clear the cache and reload the site)
0
votes

I got the error because of Allow-Control-Allow-Origin: * browser extension.

0
votes

If you are running it on localhost change the port to 5000 and it will fix it

0
votes

Trying on a different browser(chrome) worked for me and clearing cache on firefox cleared the issue.

(PS: Not add the hosting URIs to Authorized JavaScript origins in API credentials would give you Error:redirect_uri_mismatch)

0
votes

It was a referrer-policy problem.

This has been such a pain for a long time to me too...

Found the issue, my website instance had a referrer policy set to no-referrer. After setting it to no-referrer-when-downgrade, the One Tap prompt showed up as expected.

https://stackoverflow.com/a/63039142/15565029

If you are using Django, SECURE_REFERRER_POLICY is 'same-origin' by default. Change it by adding the below code in your settings file.

# settings.py
SECURE_REFERRER_POLICY = 'no-referrer-when-downgrade' 

https://docs.djangoproject.com/en/3.2/ref/settings/#std:setting-SECURE_REFERRER_POLICY

0
votes

Similar to few answers at above but with screenshots. If you created project for Firebase, may also use the same steps to configure at Google Cloud Platform console.

  1. Select the project at https://console.cloud.google.com/
  2. Navigate to Credentials
  3. Click Edit button for the related OAuth 2.0 Client ID
  4. Add URI into Authorized JavaScript origins
  5. Don't forget to Save

enter image description here

enter image description here