Google OAuth 2.0 redirect_uri_mismatch error

不想你离开。 提交于 2019-11-28 10:53:33

As little as having a '/' at the end of your uri and not having the same '/' at the end in your code will throw it off.

Your site URL and the Authorized redirect URIs in developer console should be the exact match.

This kind of error occurs if one URL has www (http://www.example.com) and the other URL is non-www (http://example.com).

Other common URI mismatch are:

  • Using http:// in Authorized Redirect URIs and https:// as actual URL, or vice-versa
  • Using trailing slash (http://example.com/) in Authorized Redirect URIs and not using trailing slash (http://example.com) as actual URL, or vice-versa

Here is the step-by-step procedure (with screenshots) to update the Authorized redirect URIs in Google Developer Console (For those like me who found it difficult to get to that page).

  1. Go to https://console.developers.google.com

  2. Select your Project

  1. Click on the menu icon

  1. Click on API Manager menu

  1. Click on Credentials menu. And under OAuth 2.0 Client IDs, you will find your client name. In my case, it is Web Client 1. Click on it and a popup will appear where you can edit Authorized Javascript Origin and Authorized redirect URIs.

Here is a Google article on creating project and client ID.

It should be a exact match what you have given in the console.developers.com.

In my case I missed the www in the url.

For eg: you have given http://www.google.com but in console.developers.com you gave http://google.com

It will still throw error. So it should be exact match.

The redirect URI (where the OAuth response is returned to) has to be registered in Google APIs console, and the error is indicating that you haven't done that, or haven't done it correctly.

Go to the console for your project and look under API Access. You should see your client ID & secret there, along with a list of redirect URIs. If the URI you want isn't listed, click edit settings and add the URI to the list.

I kept getting this same error until I realized that I needed to put "signin-google" at the end of the redirect setting in the Google API console, like this (ie, NOT http://www.example.org/api):

http://www.example.org/api/signin-google

Please make sure that in your google-client-api, the value of credentials in these field are matched as what you got from Google API console:

$client->setClientId('xxx.apps.googleusercontent.com');
$client->setClientSecret('xxx');
$client->setRedirectUri('http://example.com/oauth2callback');
$client->setDeveloperKey('xx');

This could happen when the value of setRedirectUri is different from the one you set in Google API console.

Afjal khan

(Magento 1.*) if You use inchoo Social Connect Magento extension then:

  • Set below url in your google app (OAuth 2.0 client IDs):
    1. Authorized Redirect URIs: http://www.example.com/socialconnect/google/connect/
    1. Authorized JavaScript Origins: http://www.example.com

Don’t forget to replace http://www.example.com with your domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!