问题
I created a Google OAuth 2.0
ClientID
andsecret
in Google Developer consoleAfter that I tested in Google OAuth playground (https://developers.google.com/oauthplayground). and registered
ClientID
andsecret
already created above and applied to Google OAuth 2.0 playground setting menu.Some people say that after creating
ClientID
/secret
they need some time for testing. So after two days I tried to test in the same conditions but the error is sameredirect_uri_mismatch
.
How can I solve this?
回答1:
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.
回答2:
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 andhttps://
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).
Go to https://console.developers.google.com
Select your Project
- Click on the menu icon
- Click on
API Manager
menu
- Click on
Credentials
menu. And underOAuth 2.0 Client IDs
, you will find your client name. In my case, it isWeb 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.
回答3:
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.
回答4:
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.
回答5:
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
回答6:
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.
回答7:
(Magento 1.*) if You use inchoo Social Connect Magento extension then:
- Set below url in your google app (
OAuth 2.0
client IDs): - Authorized Redirect URIs:
http://www.example.com/socialconnect/google/connect/
- Authorized Redirect URIs:
- Authorized JavaScript Origins:
http://www.example.com
- Authorized JavaScript Origins:
Don’t forget to replace http://www.example.com
with your domain
来源:https://stackoverflow.com/questions/21224946/google-oauth-2-0-redirect-uri-mismatch-error