Getting error redirect_uri_mismatch when using oAuth

Hello,

I am facing an issue with Google OAuth authentication in a production environment and would appreciate some assistance. Here is a summary of the problem and the steps I have taken so far:

Problem: I have implemented Google OAuth authentication for my web application running on an Ubuntu 22.04 server with Apache. The authentication works perfectly fine when running the application on my local machine, but it fails to work in the production environment.

Steps taken:

  1. Implemented Google OAuth using the Passport.js library in Node.js.
  2. Set up the necessary client ID and client secret in the Google Cloud Console.
  3. Configured the authorized JavaScript origins and redirect URIs in the Google Console.
  4. Verified that the server firewall rules allow outgoing connections to external servers, including the Google OAuth server.
  5. Checked the Apache server logs, but found no errors or relevant information related to the Google OAuth issue.
  6. Restarted the Apache web server and verified that the SSL certificate (Let's Encrypt) is correctly configured.

However, despite these efforts, the Google OAuth authentication continues to fail in the production environment. The authentication flow gets redirected to the Google login page, where I get the error: 'redirect_uri_mismatch'.

I would greatly appreciate any insights or guidance on how to resolve this issue and enable successful Google OAuth authentication in the production environment.

Thank you for your assistance.

1 2 14.6K
2 REPLIES 2

Hello @Ishchai,

Welcome to Google Cloud Community!

You are getting the "Error 400: redirect URI mismatched" because the redirect URI specified in your app's configuration does not match the redirect URI provided in your authorization process.


Required

Determines where the API server redirects the user after the user completes the authorization flow. The value must exactly match one of the authorized redirect URIs for the OAuth 2.0 client, which you configured in your client's API Console Credentials page. If this value doesn't match an authorized redirect URI for the provided client_id you will get a redirect_uri_mismatch error.

Note that the http or https scheme, case, and trailing slash ('/') must all match.



To resolve this, you need to attach your redirect URI value to your API key. 

Check the configuration of your application, particularly the redirect URI. Ensure that the redirect URI specified in your application matches the redirect URI you are providing during the authorization process. Pay attention to any differences in the URL scheme (HTTP vs. HTTPS), port number, or additional path segments.

"The value must exactly match one of the authorized redirect URIs for the OAuth 2.0 client, which you configured in your client's API Console Credentials page. "

Apparently the place to configure a redirect uri has been moved. It's not on the credentials page and it's no in the details for any of the keys I have listed. I've looked all over the cloud console and cannot find it. Do you happen to know where it is?