Search code examples
phplaravelgoogle-cloud-platformgoogle-oauth

PHP Laravel Google OAuth gives error for some users


I own www.sweai.se

I integrated Google login, and it works for me, friends, wife etc. No issues. However one user reported redirect error, and today I got a spike in users and I got a few reporting the error you can see in the picture. I set my redirect url to https://sweai.se/Google/callback and that has worked for 80% of my users. So why do some users get this error?

I need help to fix this error. I tried adding a new redirect URI.

enter image description here


Solution

  • I set my redirect url to https://sweai.se/Google/callback and that has worked for 80% of my users, why does some users get this error ?

    Check the error message carefully - the URL mentioned in there is https://www.sweai.se/Google/callback, and that is not the one you configured in your app settings.

    Your site appears to be accessible via https://sweai.se/ and https://www.sweai.se/ - and neither one automatically redirects to the other.

    So I'm guessing the redirect URI gets determined "dynamically" by your system - and depending on whether the user accessed your site with the www. prefix or not, the resulting redirect URI will either be https://www.sweai.se/Google/callback or https://sweai.se/Google/callback

    The "quick fix" would be that you add https://www.sweai.se/Google/callback as a valid redirect URI in your app settings.

    In the long term you should probably redirect https://www.sweai.se/ to https://sweai.se/ (or vice versa, whichever you prefer) - not only regarding this specific problem, but also concerning issues like "duplicate content" in search engines.