Search code examples
spring-bootoauth-2.0google-oauthgoogle-developers-consolegoogle-cloud-console

Google OAuth2 integration Error 400: redirect_uri_mismatch


I'm getting this error Error 400: redirect_uri_mismatch even after giving the proper redirect uri. You can check the images below for the reference. It works for my localhost but it shows this error for my server. My domain looks like https://xxx.topLevelDomain.com. I'm not able to find the possible cause of this issue after surfing most of the issues related to this error. Although, I guess the issue maybe because I'm using a subdomain here, but still not sure if its the issue.

Application info:

  • frontend is in react hosted on https://someTopLevelDomain.com
  • backend is in spring boot hosted on https://someSubdomain.someTopLevelDomain.com

enter image description here

enter image description here


Solution

  • Your application is sending from as http to a .com domain

    enter image description here

    In google developer console you have only one http domain listed and that is localhost

    enter image description here

    The redirect uri you are sending from must exactly match one that you have added in google cloud console.

    To understand how to set up your redirect uri properly check Google OAuth2: How the fix redirect_uri_mismatch error. Part 2 server sided web applications.

    where is the redirect uri comming from

    Depending upon the programing language, the ide and the client library you may be using will define what redirect uri your application is calling from.

    For example i know that visual studio likes to add random ports with C#. I cant tell you what is generating your redirect uri i can only tell you that

    The following needs to be added to your google cloud console.

    http://________.com/login/oauth2/code/Google   
    

    or you need to figuer out what is setting the host on your requests and set it to use https so that you can use the one that you have there now

    https://________.com/login/oauth2/code/Google