1

i am trying to implement Google OAuth into my project, and i already configured the project in the google cloud console, setup the OAuth client secrets/Id and also the redirect uri.

The problem is, when the Google login pops-up, it throws the following error:

400 redirect_uri_mismatch

And this only happens when i set the authorized redirect url, in the google cloud console, to a uri different than

https://127.0.0.1/authorize

The errors: enter image description here

The redirect uri i have added: enter image description here

Here are my port settings in visual studio: enter image description here

filipe
  • 139
  • 2
  • 17

1 Answers1

1

redirect_uri_mismatch is a very common error message.

The redirect uri defiles the end point in your app where you would like the authorization to be returned to. This endpoint must be properly configured in google cloud console.

If your application sends https://127.0.0.1/authorize and that endpoint isnt configured within google cloud console there will be a miss match.

The best solution is to copy which ever miss match URL the error told you and add that in Google cloud console. Remember it must match exactly HTTP is not the same as HTTPS if there is a trailing slash you will need that as well. It must match exactly.

What you need to understand is that it works with https://127.0.0.1/authorize because that is the uri that your code is using. So dont change it.

This video will explain the cause of the error and how to fix it. Google OAuth2: How the fix redirect_uri_mismatch error. Part 2 server sided web applications.

Just remember when you release this to production you will not be allowed to have a localhost redirect uri you will need to set it at that time to the domain you are hosting it on.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • thanks for you response btw. So, from the advice you gave me, i went and used the uri that the redirect_uri_mismatch points to that it was http://127.0.0.1:57658/authorize/ After that, i still got the error and it was pointing to another port now... http://127.0.0.1:57786/authorize/ BTW my project base uri is https://localhost:4325 – filipe Dec 02 '21 at 10:54
  • And everytime i try to reproduce the error, the port of the URl that it mismatches, changes – filipe Dec 02 '21 at 11:00
  • As i mentioned it must match exactly. Your IDE is changing your port. You need to set it to run with a static port, as the redirect uri needs to match exactly. – Linda Lawton - DaImTo Dec 02 '21 at 11:28
  • So, i saw the same comment someone made in your video about that, and you answered the same, but i can´t seem do find the option for that, my project seems to run everytime the port as 44325, fixed basically. Have you got any resource where i can set the port to be static? – filipe Dec 02 '21 at 11:49
  • What IDE are you using? – Linda Lawton - DaImTo Dec 02 '21 at 12:03
  • i am using Visual Studio 2019 – filipe Dec 02 '21 at 12:39
  • try this https://stackoverflow.com/a/1126560/1841839 I use JetBrains Rider and have it always set to static port to avoid this issue myself – Linda Lawton - DaImTo Dec 02 '21 at 12:41
  • sooo, i did that solution, but still got the same error. Just a quick question, my app in the google cloud console, is still not approved, is that one of the reasons that they only allow localhost? – filipe Dec 02 '21 at 13:27
  • can you put up a screen shot of the error you are getting and the redirect uris you have added? – Linda Lawton - DaImTo Dec 02 '21 at 13:27
  • I have added the screenshots, hope it's good enough, thanks again for the patience... Sry some things are in foreign... it´s portuguese – filipe Dec 02 '21 at 13:41
  • http://127.0.0.1:59173/authorize/ is not in the list of your valid redirect uris. Check the port. (don't worry about the language sometimes mine are in Danish, the message i standard) – Linda Lawton - DaImTo Dec 02 '21 at 13:44
  • ok, no problem. So i added the redirect uri, that indicated, but now it says the mismatch it's with this one http://127.0.0.1:59262/authorize/ – filipe Dec 02 '21 at 13:48
  • yes because your port is still changing set visual studio to stop changing ports. You need to have it run with the same port every time or you are going to keep getting this error. – Linda Lawton - DaImTo Dec 02 '21 at 14:14
  • I added my VS settings for the project, fyi, i already tried using the non-ssl port – filipe Dec 02 '21 at 14:57