How to solve: Error 400 - redirect_uri_mismatch in Google Console

Published on: January 27, 2025

How to Resolve the "Error 400: redirect_uri_mismatch" in Google Console

When setting up your application to work with Google APIs, encountering the error "Error 400: redirect_uri_mismatch" can be frustrating. This error typically occurs when the redirect URI specified in your application does not match one of the Authorized Redirect URIs configured in the Google API Console.

In this guide, we’ll walk you through understanding and resolving this issue effectively.


What Causes the "redirect_uri_mismatch" Error?

The error happens because the URI your app is trying to use for the OAuth 2.0 flow is not recognized by Google. This mismatch might be due to inconsistencies such as:

  • Typos in the URI.
  • Differences in protocols (e.g., http vs https).
  • Missing trailing slashes.
  • Incorrect configuration for multiple environments (e.g., development, staging, production).

To fix this, ensure that the redirect URI in your application matches exactly with the one specified in the Google API Console.


Step-by-Step Solution

Follow these steps to resolve the issue:

1. Check the Redirect URI in Your Application

Your application’s OAuth configuration should have a redirect URI defined. This is the URI where the user is redirected after they’ve authenticated with Google. Locate this URI in your application and make note of it.

2. Verify Redirect URI Configuration in Google API Console

  1. Go to the Google API Console.
  2. Select your project.
  3. In the left-hand menu, click on Credentials.
  4. Locate the OAuth 2.0 Client ID associated with your application and click Edit.
  5. Under Authorized redirect URIs, ensure the URI from your application is listed exactly.

    Important: The redirect URI must match in its entirety, including:

    • Whether it uses http or https.
    • Presence or absence of trailing slashes.
    • Port numbers (if applicable).

3. Add All Relevant URIs for Multiple Environments

If you’re working with multiple environments (e.g., development, staging, production), you’ll need to add each environment’s redirect URI to the Authorized redirect URIs list. For example:

  • https://dev.example.com/callback
  • https://staging.example.com/callback
  • https://example.com/callback

4. Align with AWS Cognito Settings

If your app is using AWS Cognito, ensure the following:

  • Google API Console: Add the same URIs that are listed under Cognito’s Allowed Callback URLs and Allowed Sign-out URLs.
  • Cognito Configuration: Double-check the URIs to confirm they match exactly with what you’ve entered in the Google API Console.

5. Ensure Consistency Across Platforms

For OAuth flows to function seamlessly, your configuration must be consistent across:

  • Google API Console
  • Your application’s settings
  • AWS Cognito (if applicable)

6. Account for Propagation Time

After making changes in the Google API Console, it might take a few minutes for the settings to propagate. Be patient and test again after some time if you’ve recently updated the configuration.

7. Use the Correct Client ID

Ensure that your application is using the correct Client ID. Each Client ID is associated with a specific set of redirect URIs in the Google API Console. Using the wrong Client ID can also result in a mismatch error.


Additional Resources

To further troubleshoot or refine your configuration, check out the following resources:


Final Thoughts

The Error 400: redirect_uri_mismatch is a common roadblock when configuring Google APIs, but it’s easily resolved with proper attention to detail. By ensuring that your redirect URIs match exactly across your application, Google API Console, and any third-party services like AWS Cognito, you can quickly overcome this issue and get back to building your application.

If you have further questions or run into additional challenges, feel free to leave a comment below or consult the official documentation linked above. Good luck with your integration!

Left Linker Right Linker