Google OAuth 2 Authentication lets users give permission to other apps without sharing their passwords. But sometimes, it can have problems. A common issue is the error 400 redirect_uri_mismatch.
To fix this, we’ll explain what this error means and share a step-by-step guide.
What is error 400 redirect_uri_mismatch?
The 400 error happens when the URI in the Google Developer Console doesn’t match the one in the app code. This causes an Error 400 because the authorization codes can’t be swapped properly.
To understand this error better, let’s delve into how Google OAuth 2 Authentication works.
Google OAuth 2 Authentication lets users let other apps use their Google account without giving away their password. When a user wants to connect an app, the app sends them to Google’s special login page.
There, the user puts in their Google login details and says “yes” to the app using their account.
Also Check: Error 503 Backend Fetch Failed
Google OAuth 2 Authentication Explained
Understanding Google OAuth 2 Authentication:
- Setting up the app: Developers tell Google about their app and get a special ID and secret code from the Google Developer Console.
- Asking for permission: When a user tries to use the app, Google shows them a screen. This screen asks if the app can have certain permissions.
- Getting access: If the user says “yes”, the app gets a code from Google. The app swaps this code for two other codes (tokens) that let it use Google features for the user.
- Keeping access: These tokens don’t last forever. But when they run out, the app can use one of them (the refresh token) to get a new one. This means the user doesn’t have to keep giving permission..
What Causes error 400 redirect_uri_mismatch?
Several factors can contribute to the occurrence of the “redirect_uri_mismatch” error. Let’s explore the most common causes:
- Wrong URI in the App: Sometimes, developers put the wrong redirect link in their app, which doesn’t match what’s on the Google Developer Console.
- Many URIs in Use: If an app uses several redirect links, developers need to make sure each one matches what’s on the Google Developer Console.
- Not Updating URIs Properly: As time goes by, the links in the app and the Google Developer Console might not be kept in sync.
- Changes in the Google Developer Console: If changes are made to the URI settings in the console without updating the app, it can cause errors.
Also Check: Error Code 0X887A0005
How to Fix error 400 redirect_uri_mismatch?
- Enter Authorized Redirect URIs:
- First, open your web browser and go to the Google API Console.
- Look at the top-left corner of the page to find and select the correct project from the drop-down list.
- Navigate to the “APIs & Services” from the left-hand side menu, then click on the “Credentials” tab.
- Find the OAuth Client Id you created in the list and click on it to open its settings.
- Look for the “Authorized redirect URIs” section, then click on the “Add URI” button.
- In the provided field, type in your authorized redirect URI, then click on the “Save” button at the bottom of the page.
- Add URL from the Error Message:
- On the error message you received, locate and copy the exact URL mentioned.
- Go back to the “Authorized redirect URIs” section in the Google API Console under the credentials of your OAuth Client Id.
- Click on the “Add URI” button, paste the URL from the error message into the field, then click on the “Save” button at the bottom of the page.
- Enter a Variety of URLs:
- In the “Authorized redirect URIs” section in the Google API Console, click on the “Add URI” button.
- Enter various versions of your URL, considering the following variations:
- With and without a trailing slash (e.g.,
- With and without “www” (e.g.,
- With and without a trailing slash (e.g.,
- After entering all variations, click on the “Save” button at the bottom of the page.
- Check Project and Credentials:
- Ensure you are working on the correct project by checking the project name at the top-left corner of the Google API Console.
- Navigate to the “Credentials” tab, then click on the OAuth Client Id you created.
- Double-check the listed “Authorized redirect URIs” to ensure they match the URIs you want to use.
- Use API Console to Update Redirect URIs:
- Go to the console for your project, and under “API Access”, locate your client ID and secret.
- Check the list of redirect URIs, and if the URI you want isn’t listed, click “edit settings”.
- Add the URI to the list, then click “Save” to update the settings.
- Consider OAuth 2.0 Authorization Changes:
- If using Azure AD B2C along with MSAL sdk for native Android and iOS Applications, check for any recent changes in Google’s OAuth 2.0 authorization that might require an update in your configurations.
- Ensure that the configurations for Google Single Sign-On (SSO) are correctly set up, and the redirect URIs in Azure AD B2C match those registered in the Google API Console.
Also Check: Error Code 102630
Getting the “redirect_uri_mismatch” error 400 while using Google OAuth 2 Authentication can be annoying. But knowing what causes this error and how to fix it can help. Following the steps shared can help developers get through this issue and make the login process for their apps smooth.
By following these guidelines, fixing the error becomes easier. This way, you can use Google OAuth 2 Authentication better in your app. Fixing this error helps make your app better and more secure.
Google OAuth 2 error 400 redirect_uri_mismatch FAQ’s
This error occurs when the redirect URL in your request doesn’t match any redirect URLs listed in your Google API Console for your OAuth 2.0 client. It’s a way to ensure only authorized URLs are used.
Go to the Google API Console, select your project, navigate to “Credentials”, click on your OAuth Client Id, and in the “Authorized redirect URIs” section, add the correct redirect URI. Then click “Save”.
Try adding variations of your URL in the “Authorized redirect URIs” section, like versions with/without a trailing slash or with/without “www”. Then click “Save” and test again.
Make sure you are working on the correct project in the Google API Console and the OAuth Client Id you are editing is the right one. Also, check for any recent updates in Google OAuth 2.0 authorization that might need new configurations.
Yes, you can add multiple redirect URIs in the “Authorized redirect URIs” section in Google API Console to handle different login redirects, which can help prevent this error from happening again.