Search code examples
spring-securityoauth-2.0google-developers-console

im receivin an redirect uri mismatch when using oauth2 google


Good day

I've been trying to set oauth2 using springBoot and authentication through google account. However, after setting everything in local and test correct functionality, it fails when i tried to test on server.

i have been receiving "Error 400: redirect_uri_mismatch", but not aditional information is being shown Error received

Also, as authentication worked on local, i just added url's to server on google app

myserverurl(not real in picture) aims to my server

as its shown, url's to redirect are added, and i dont know what else to try. Anyone knows why? i will really appreciate the help


Solution

  • You have 2 stages of your deployment pipeline here:

    • Developer local PC
    • Deployed environment

    In the deployed environment, this is happening:

    • Your are redirecting on http://myserverurl:8080
    • Google is selecting the first redirect URI to return the login response on
    • This is http://localhost:8080, leading to the error

    The preferred way to resolve your problem is to ensure that you create multiple OAuth client entries in the Authorization Server console, all with independent settings and a single / consistent host name:

    • MyWebApp (DeveloperLocalPC)
    • MyWebApp (DeployedTestEnvironment)
    • MyWebApp (DeployedProductionEnvironment)